﻿Imports System.Data.SqlClient
Imports System.Data.Odbc

Public Class frmModuloEmpleadosDetalle
    Dim Bitacora As New clsActividad
    Dim Usuario As New clsUsuarioPrincipal
    Dim cont As Integer
    Dim cont2 As Integer
    Dim limite As Integer
    Dim Empleados As New clsEmpleados
    Dim Incapacidad As New clsIncapacidades
    Dim CInfonavit As New clsCargosInfonavit
    Dim CFonacot As New clsCargosFonacot
    Dim PInfonavit As New clsPeriodoInfonavit
    Dim pFonacot As New clsPeriodoFonacot
    Dim Repo As New clsReportesOperadores
    Dim Mov As New clsMovimientos
    Dim Obs As New clsObservaciones
    Dim Lice As New clsLicencia
    Dim Fianzas As New clsFianzasvb

    Private Sub frmModuloEmpleadosDetalle_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Bitacora.RegistraActividad("Cerró al Módulo de Personal_: Expediente del empleado")
        Usuario.Ubicacion("Módulo de Personal")

        frmMain.statusActividad.Text = ": Módulo de Personal"
    End Sub
    Sub FormateaGrids()
        dgIncapacidades.Columns(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        dgInfonavitNEW.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgInfonavitNEW.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgInfonavitNEW.Columns(3).DefaultCellStyle.Format = "###,###.#0"

        dgFonacotNEW.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgFonacotNEW.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgFonacotNEW.Columns(3).DefaultCellStyle.Format = "###,###.#0"

        dgInfonavit.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgInfonavit.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgInfonavit.Columns(2).DefaultCellStyle.Format = "###,###.#0"
        dgInfonavit.Columns(3).DefaultCellStyle.Format = "###,###.#0"

        dgFonacot.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgFonacot.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgFonacot.Columns(2).DefaultCellStyle.Format = "###,###.#0"
        dgFonacot.Columns(3).DefaultCellStyle.Format = "###,###.#0"

        dgIncidente.Columns(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgIncidente.Columns(7).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgIncidente.Columns(8).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
        dgIncidente.Columns(7).DefaultCellStyle.Format = "###,###.#0"
        dgIncidente.Columns(8).DefaultCellStyle.Format = "###,###.#0"



    End Sub
    Sub Muestra_OcultaTabs()
        Dim Codigo As String = txtCodigo.Text
        Dim IDPeriodo As Integer = BuscarIntDatoNominas("NOM10001", "IdTipoPeriodo", "CodigoEmpleado='" & Codigo.Trim & "'")

        If IDPeriodo = 2 Then
            TabPage3.Parent = TabControl1
            TabPage9.Parent = TabControl1
        ElseIf IDPeriodo = 4 Then
            TabPage3.Parent = TabControl1
            TabPage9.Parent = TabControl1
        Else
            TabPage3.Parent = Nothing
            TabPage9.Parent = Nothing
        End If

    End Sub

    Private Sub frmModuloEmpleadosDetalle_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    End Sub
    Sub CargaEstados()
        Dim cnconn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strSql As String
        Try
            cnconn.ConnectionString = InitialConnection
            strSql = "Select ESTADOS FROM ESTADOS ORDER BY ESTADOS"

            cmdBuscar.Connection = cnconn
            cmdBuscar.CommandText = strSql

            cnconn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                txtEstado.AutoCompleteCustomSource.Add(rdBuscar("ESTADOS").ToString.Trim)

            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try

    End Sub
    Private Sub frmModuloEmpleadosDetalle_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        TabPage1.Select()

        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip1.Stretch = True

        Bitacora.RegistraActividad("Ingresó al Módulo de Personal: Expediente del empleado")
        Usuario.Ubicacion("Módulo de Personal: Expediente del empleado")

        FormateaGrids()

        'Alinear TEXTBOX
        txtSD.TextAlign = HorizontalAlignment.Right
        txtSDI.TextAlign = HorizontalAlignment.Right
        txtPorcentaje.TextAlign = HorizontalAlignment.Right
        txtNumero.TextAlign = HorizontalAlignment.Right
        txtCodigoPostal.TextAlign = HorizontalAlignment.Right
        txtFianza.TextAlign = HorizontalAlignment.Right
        txtMontoFonacot.TextAlign = HorizontalAlignment.Right
        txtMontoInfonavit.TextAlign = HorizontalAlignment.Right

        cargaAdeudos()
        CargaEstados()
        CargaLugaresNacimiento()

        If EmpleadoNuevo = True Then
            frmMain.statusActividad.Text = ": Registrando un nuevo empleado"
            txtCodigo.Enabled = True
            txtPaterno.Enabled = True
            txtMaterno.Enabled = True
            txtNombre.Enabled = True
            txtDepartamento.Enabled = True
            txtPuesto.Enabled = True
            btnDepto.Enabled = True
            btnPuesto.Enabled = True
            txtSD.Enabled = True
            txtSDI.Enabled = False
            txtFechaCURP.Enabled = False
            txtFechaRFC.Enabled = False

            LimpiaCampos()
            EmpleadoID = (BuscarIntDatoCitra("SELECT MAX(IdEmpleado) as IdEmpleado FROM Empleados")) + 1
            Me.txtIDEmpleado.Text = EmpleadoID
            Muestra_OcultaTabs()
            Actualizar()
            txtSD.Text = 0
            txtNumero.Clear()
            txtColonia.Clear()

            AccionesToolStripMenuItem.Visible = False
            AccionesToolStripMenuItem1.Visible = False
            InformesToolStripMenuItem.Visible = False
            ToolStripButton3.Visible = False
            ToolStripButton2.Visible = False

            Me.txtIDEmpleado.Enabled = False
            txtStatus.Text = "Alta"
            txtStatus.Enabled = True
            Me.pbFoto.Image = Nothing
            Me.lstEscolaridad.Visible = True
            Me.Label37.Visible = True
            Me.txtTarjeton.Enabled = True
            Me.RadDropDownButton3.Enabled = False

            TabPage2.Parent = Nothing
            TabPage3.Parent = Nothing
            TabPage4.Parent = Nothing
            TabPage5.Parent = Nothing
            TabPage6.Parent = Nothing
            TabPage7.Parent = Nothing
            TabPage8.Parent = Nothing
            TabPage9.Parent = Nothing
            TabPage10.Parent = Nothing
            TabPage11.Parent = Nothing
            TabPage12.Parent = Nothing

            chGafete.Checked = False
            datVencimientoGafete.Enabled = True
        Else
            frmMain.statusActividad.Text = ": Expediente virtual del empleado"
            AccionesToolStripMenuItem.Visible = True
            AccionesToolStripMenuItem1.Visible = True
            InformesToolStripMenuItem.Visible = True
            ToolStripButton3.Visible = True
            ToolStripButton2.Visible = True

            TabPage2.Parent = TabControl1
            TabPage3.Parent = TabControl1
            TabPage4.Parent = TabControl1
            TabPage5.Parent = TabControl1
            TabPage6.Parent = TabControl1
            TabPage7.Parent = TabControl1
            TabPage8.Parent = TabControl1
            TabPage9.Parent = TabControl1
            TabPage10.Parent = TabControl1
            TabPage11.Parent = TabControl1
            TabPage12.Parent = TabControl1

            txtCodigo.Enabled = False
            txtPaterno.Enabled = False
            txtMaterno.Enabled = False
            txtNombre.Enabled = False
            txtDepartamento.Enabled = False
            txtPuesto.Enabled = False
            btnDepto.Enabled = True
            btnPuesto.Enabled = True
            txtSD.Enabled = False
            txtSDI.Enabled = False
            txtFechaCURP.Enabled = False
            txtFechaRFC.Enabled = False


            txtIDEmpleado.Text = EmpleadoID
            Application.DoEvents()
            Actualizar()
            cont = 0
            cont2 = 0
            limite = frmModuloEmpleados.dgEmpleados.Rows.Count - 1
        End If

    End Sub
    Sub CargaDatosDesdeNominas()
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = NominasConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * FROM NOM10001 WHERE CodigoEmpleado='" & txtCodigo.Text & "'"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        If rdBuscar.Read Then
            txtNombre.Text = rdBuscar("Nombre")
            txtPaterno.Text = rdBuscar("ApellidoPaterno")
            txtMaterno.Text = rdBuscar("ApellidoMaterno")
            datIngreso.Value = rdBuscar("FechaAlta")
            txtDepartamento.Text = BuscarStrDatoNominas("NOM10003", "Descripcion", "IdDepartamento=" & rdBuscar("IdDepartamento"))
            txtPuesto.Text = BuscarStrDatoNominas("NOM10006", "Descripcion", "IdPuesto=" & rdBuscar("IdPuesto"))
            txtSD.Text = rdBuscar("SueldoDiario")
            txtSD.Text = Format(rdBuscar("SueldoDiario"), "###,###.#0")
            txtSDI.Text = rdBuscar("SueldoIntegrado")
            txtSDI.Text = Format(rdBuscar("SueldoIntegrado"), "###,###.#0")

            Dim Status As String = rdBuscar("EstadoEmpleado")
            If Status = "A" Then
                txtStatus.Text = "Alta"
            ElseIf Status = "B" Then
                txtStatus.Text = "Baja"
            Else
                txtStatus.Text = "Reingreso"
            End If

            Dim domi As String = rdBuscar("Direccion")
            Dim str() As String
            Try
                str = Split(domi, ",", 3)
                Me.txtCalle.Text = str(0)
                Me.txtNumero.Text = LTrim(str(1))
                Me.txtColonia.Text = str(2)
            Catch ex As Exception

            End Try

            str = Nothing
            txtCiudad.Text = rdBuscar("Poblacion")
            txtEstado.Text = rdBuscar("Estado")
            txtTelefono.Text = rdBuscar("Telefono")
            txtCelular.Text = ""
            txtRecados.Text = ""
            txtCodigoPostal.Text = rdBuscar("CodigoPostal")
            datNacimiento.Value = rdBuscar("FechaNacimiento")
            txtNacimiento.Text = rdBuscar("LugarNacimiento")
            Dim estadoCivil As String = rdBuscar("EstadoCivil")
            Select Case estadoCivil
                Case "C"
                    Me.lstEstadoCivil.Text = "Casado(a)"
                Case "S"
                    Me.lstEstadoCivil.Text = "Soltero(a)"
                Case "D"
                    Me.lstEstadoCivil.Text = "Divorciado(a)"
                Case "V"
                    Me.lstEstadoCivil.Text = "Viudo(a)"
            End Select

            Dim sexo As String = rdBuscar("Sexo")
            Select Case sexo
                Case "M"
                    Me.lstSexo.Text = "Masculino"
                Case "F"
                    Me.lstSexo.Text = "Femenino"
            End Select
            Me.txtRFC.Text = rdBuscar("RFC")
            Dim escuela As String = ""
            Dim inde As Integer
            Select Case escuela.Trim
                Case "Primaria"
                    inde = 0
                Case "Secundaria"
                    inde = 1
                Case "Preparatoria"
                    inde = 2
                Case "Licenciatura (Profesional)"
                    inde = 3
            End Select
            lstEscolaridad.Items.Clear()
            lstEscolaridad.Items.Add("Primaria")
            lstEscolaridad.Items.Add("Secundaria")
            lstEscolaridad.Items.Add("Preparatoria")
            lstEscolaridad.Items.Add("Licenciatura (Profesional)")
            lstEscolaridad.SelectedIndex = inde
            lstEscolaridad.Text = ""

            Dim FechaParaDatos As Date = rdBuscar("FechaNacimiento")
            Dim FechaTexto As String = ""
            FechaTexto = Mid(FechaParaDatos.Year, 3, 2)
            If FechaParaDatos.Month < 10 Then
                FechaTexto = FechaTexto & "0" & FechaParaDatos.Month
            Else
                FechaTexto = FechaTexto & FechaParaDatos.Month
            End If

            If FechaParaDatos.Day < 10 Then
                FechaTexto = FechaTexto & "0" & FechaParaDatos.Day
            Else
                FechaTexto = FechaTexto & FechaParaDatos.Day
            End If

            txtFechaRFC.Text = FechaTexto
            txtFechaCURP.Text = FechaTexto

            txtHomoclave.Text = rdBuscar("Homoclave")
            txtCURP.Text = rdBuscar("CURPI")
            txtCURPF.Text = rdBuscar("CURPF")
            txtCuentaPago.Text = rdBuscar("CuentaPagoElectronico")
            txtCuentaContPAQ.Text = rdBuscar("CuentaCW")
            txtNSS.Text = rdBuscar("NumeroSeguroSocial")
            txtPorcentaje.Text = 0

            LimpiaCampos()

            txtLicencia.Text = ""
            txtTarjeton.Text = ""
            If txtLicencia.Text <> "" Then
                txtTipoLicencia.Text = "B"
            Else
                txtTipoLicencia.Text = ""
            End If

            Try
                datVencimientoLicencia.Value = Now()
            Catch ex As Exception

            End Try



            dgEdoCta.Rows.Clear()

            Me.txtFianza.Text = 0
        End If

       
    End Sub
    Sub CargaObservaciones()
        Me.dgObservaciones.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Observaciones " & _
        " WHERE idempleado=" & EmpleadoID

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim Fecha As Date


        Do While rdBuscar.Read()
            Fecha = rdBuscar("fecha")
            Me.dgObservaciones.Rows.Add(rdBuscar("idObservacion"), Fecha.ToShortDateString, rdBuscar("observacion"))
        Loop
    End Sub
    Sub cargaOtros()
        Me.dgOtros.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From OtrosCargos " & _
        " WHERE idempleado=" & EmpleadoID & " order by fecha"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechaincidente As Date
        Dim tiempo As String
        Dim tipo As String

        Do While rdBuscar.Read()
            fechaincidente = rdBuscar("fecha")
            tipo = rdBuscar("tipo").ToString.Trim
            If tipo = "Semanal" Then
                tipo = "Semana(s)"
            ElseIf tipo = "Diario" Then
                tipo = "Dia(s)"
            Else
                tipo = "Catorcena(s)"

            End If
            tiempo = rdBuscar("tiempo") & " " & tipo
            Me.dgOtros.Rows.Add(rdBuscar("idCargo"), fechaincidente.ToShortDateString, rdBuscar("motivo"), rdBuscar("monto"), tiempo, rdBuscar("descuento"))
        Loop
    End Sub

    Sub cargagratificaciones()
        Me.dgGratificacion.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Gratificaciones " & _
        " WHERE IdEmpleado=" & EmpleadoID & " order by fecha"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechaincidente As Date

        Do While rdBuscar.Read()
            fechaincidente = rdBuscar("fecha")
            Me.dgGratificacion.Rows.Add(rdBuscar("idGratificacion"), fechaincidente.ToShortDateString, rdBuscar("tipo"), rdBuscar("monto"), rdBuscar("tipohora"), rdBuscar("motivo"))
        Loop
    End Sub
    Sub cargaIncapacidades()
        Me.dgIncapacidades.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Incapacidades " & _
        " WHERE idempleado=" & EmpleadoID

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim Inicio As Date
        Dim Fin As Date

        Try
            Do While rdBuscar.Read()
                Inicio = rdBuscar("FechaInicio")
                Fin = rdBuscar("FechaFin")
                dgIncapacidades.Rows.Add(rdBuscar("idIncapacidad"), rdBuscar("serie").ToString.Trim, rdBuscar("Motivo").ToString.Trim, rdBuscar("Tipo").ToString.Trim, Inicio.ToShortDateString, rdBuscar("dias"), Fin.ToShortDateString, rdBuscar("Descripcion").ToString.Trim)
            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

    End Sub
    Sub CargaInfonavit()
        Me.dgInfonavitNEW.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From CargosInfonavit " & _
        " WHERE IdEmpleado=" & EmpleadoID & " order by Fecha"

        Dim rdBuscar As SqlDataReader
        Dim FECHA As Date

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            FECHA = rdBuscar("Fecha")
            dgInfonavitNEW.Rows.Add(rdBuscar("IdCargoInfonavit"), FECHA.Day & "/" & FECHA.Month & "/" & FECHA.Year, rdBuscar("Bimestre"), rdBuscar("Monto"))
        Loop

    End Sub
    Sub CargaFonacot()
        Me.dgFonacotNEW.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From CargosFonacot " & _
        " WHERE IdEmpleado=" & EmpleadoID & " order by Fecha"

        Dim rdBuscar As SqlDataReader
        Dim FECHA As Date

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            FECHA = rdBuscar("Fecha")
            dgFonacotNEW.Rows.Add(rdBuscar("IdCargoFonacot"), FECHA.Day & "/" & FECHA.Month & "/" & FECHA.Year, rdBuscar("Mes"), rdBuscar("Monto"))
        Loop
    End Sub
    Sub CargaInfonavitOLD()
        Me.dgInfonavit.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From InfonavitFonacot " & _
        " WHERE idempleado=" & EmpleadoID & " and Tipo='INFONAVIT'"

        Dim rdBuscar As SqlDataReader
        Dim FECHA As Date

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            FECHA = rdBuscar("Fecha")
            Me.dgInfonavit.Rows.Add(rdBuscar("IdRegistro"), FECHA.Day & "/" & FECHA.Month & "/" & FECHA.Year, rdBuscar("Original"), rdBuscar("Nuevo"), rdBuscar("Motivo"))
        Loop

    End Sub
    Sub CargaFonacotOLD()
        Me.dgFonacot.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From InfonavitFonacot " & _
        " WHERE idempleado=" & EmpleadoID & " and tipo='FONACOT'"

        Dim rdBuscar As SqlDataReader
        Dim FECHA As Date

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            FECHA = rdBuscar("Fecha")
            Me.dgFonacot.Rows.Add(rdBuscar("IdRegistro"), FECHA.Day & "/" & FECHA.Month & "/" & FECHA.Year, rdBuscar("Original"), rdBuscar("Nuevo"), rdBuscar("Motivo"))
        Loop
    End Sub
    Sub Actualizar()
        Dim intFolio As Integer = 0
        If Me.txtIDEmpleado.Text <> "" Then
            intFolio = Me.txtIDEmpleado.Text
            Empleados.IDEmpleado = Me.txtIDEmpleado.Text
        Else
            intFolio = 0
            Empleados.IDEmpleado = 0
        End If
        Empleados.Buscar()
        Scatter()
        Me.txtIDEmpleado.Text = intFolio
        Empleados.IDEmpleado = Me.txtIDEmpleado.Text

    End Sub
    Sub cargaAccidentes()
        Me.dgIncidente.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Accidentes " & _
        " WHERE idempleado=" & EmpleadoID & " order by fecha"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechaincidente As Date

        Do While rdBuscar.Read()
            fechaincidente = rdBuscar("fecha")
            Me.dgIncidente.Rows.Add(rdBuscar("idAccidente"), fechaincidente.ToShortDateString, rdBuscar("lugar"), rdBuscar("tipo"), rdBuscar("autobus"), rdBuscar("causa"), rdBuscar("severidad"), rdBuscar("monto"), rdBuscar("cobro"))
        Loop

    End Sub
    Sub cargaPermisos()
        Me.dgPermiso.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Permisos " & _
        " WHERE idempleado=" & EmpleadoID & " order by dia"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechaincidente As Date

        Do While rdBuscar.Read()
            fechaincidente = rdBuscar("dia")
            Me.dgPermiso.Rows.Add(rdBuscar("idPermiso"), fechaincidente.ToShortDateString, rdBuscar("horario"), rdBuscar("tipo"), rdBuscar("observaciones"))
        Loop
    End Sub
    Sub cargaVacaciones()
        Me.dgVacacion.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Vacaciones " & _
        " WHERE idempleado=" & EmpleadoID & " order by tomafechainicial"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechai As Date
        Dim fechaf As Date
        Dim periodoi As Date
        Dim periodof As Date

        Do While rdBuscar.Read()
            fechai = rdBuscar("tomafechainicial")
            fechaf = rdBuscar("tomafechafinal")
            periodoi = rdBuscar("esfechainicial")
            periodof = rdBuscar("esfechafinal")
            Me.dgVacacion.Rows.Add(rdBuscar("idVacacion"), fechai.ToShortDateString, fechaf.ToShortDateString, rdBuscar("periodo"), periodoi.ToShortDateString, periodof.ToShortDateString, rdBuscar("observaciones"))
        Loop
    End Sub
    Private Sub Scatter()

        txtCodigo.Text = Empleados.Codigo
        txtNombre.Text = Empleados.Nombre
        txtPaterno.Text = Empleados.ApellidoPaterno
        txtMaterno.Text = Empleados.ApellidoMaterno
        datIngreso.Value = Empleados.FechaAlta
        txtDepartamento.Text = BuscarStrDatoCitra("Departamentos", "Descripcion", "IdDepartamento=" & Empleados.IdDepartamento)
        txtPuesto.Text = BuscarStrDatoCitra("Puestos", "Descripcion", "IdPuesto=" & Empleados.IDPuesto)
        Dim SD As Double = BuscarDblDatoNominas("SELECT SueldoDiario FROM NOM10001 WHERE CodigoEmpleado='" & txtCodigo.Text & "'")
        txtSD.Text = Format(SD, "###,###.#0")
        Dim SDI As Double = BuscarDblDatoNominas("SELECT SueldoIntegrado FROM NOM10001 WHERE CodigoEmpleado='" & txtCodigo.Text & "'")
        txtSDI.Text = Format(SDI, "###,###.#0")

        Dim Status As String = Empleados.EstadoEmpleado
        If Status = "A" Then
            txtStatus.Text = "Alta"
        ElseIf Status = "B" Then
            txtStatus.Text = "Baja"
        Else
            txtStatus.Text = "Reingreso"
        End If
        Dim domi As String = Empleados.Direccion
        Dim str() As String
        Try
            str = Split(domi, ",", 3)
            Me.txtCalle.Text = str(0)
            Me.txtNumero.Text = LTrim(str(1))
            Me.txtColonia.Text = str(2)
        Catch ex As Exception

        End Try

        str = Nothing
        txtCiudad.Text = Empleados.Poblacion
        txtEstado.Text = Empleados.Estado
        txtTelefono.Text = Empleados.Telefono
        txtCelular.Text = Empleados.Celular
        txtRecados.Text = Empleados.TelefonoRecados
        txtCodigoPostal.Text = Trim(Empleados.CodigoPostal)
        datNacimiento.Value = Empleados.FechaNacimiento
        txtNacimiento.Text = Empleados.LugarNacimiento
        Dim estadoCivil As String = Empleados.EstadoCivil
        Select Case estadoCivil
            Case "C"
                Me.lstEstadoCivil.Text = "Casado(a)"
            Case "S"
                Me.lstEstadoCivil.Text = "Soltero(a)"
            Case "D"
                Me.lstEstadoCivil.Text = "Divorciado(a)"
            Case "V"
                Me.lstEstadoCivil.Text = "Viudo(a)"
        End Select

        Dim sexo As String = Empleados.Sexo
        Select Case sexo
            Case "M"
                Me.lstSexo.Text = "Masculino"
            Case "F"
                Me.lstSexo.Text = "Femenino"
        End Select
        Me.txtRFC.Text = Empleados.RFC
        Dim escuela As String = Empleados.Escolaridad
        Dim inde As Integer
        Select Case escuela.Trim
            Case "Primaria"
                inde = 0
            Case "Secundaria"
                inde = 1

            Case "Preparatoria"
                inde = 2
            Case "Licenciatura (Profesional)"
                inde = 3
        End Select
        lstEscolaridad.Items.Clear()
        lstEscolaridad.Items.Add("Primaria")
        lstEscolaridad.Items.Add("Secundaria")
        lstEscolaridad.Items.Add("Preparatoria")
        lstEscolaridad.Items.Add("Licenciatura (Profesional)")
        lstEscolaridad.SelectedIndex = inde
        lstEscolaridad.Text = Empleados.Escolaridad

        Dim FechaParaDatos As Date = Empleados.FechaNacimiento
        Dim FechaTexto As String = ""
        FechaTexto = Mid(FechaParaDatos.Year, 3, 2)
        If FechaParaDatos.Month < 10 Then
            FechaTexto = FechaTexto & "0" & FechaParaDatos.Month
        Else
            FechaTexto = FechaTexto & FechaParaDatos.Month
        End If

        If FechaParaDatos.Day < 10 Then
            FechaTexto = FechaTexto & "0" & FechaParaDatos.Day
        Else
            FechaTexto = FechaTexto & FechaParaDatos.Day
        End If

        txtFechaRFC.Text = FechaTexto
        txtFechaCURP.Text = FechaTexto

        txtHomoclave.Text = Empleados.Homoclave
        txtCURP.Text = Empleados.CURP
        txtCURPF.Text = Empleados.CURPF
        txtCuentaPago.Text = Empleados.CuentaPago
        txtCuentaContPAQ.Text = Empleados.CuentaCW
        txtNSS.Text = Empleados.NSS
        txtPorcentaje.Text = Empleados.PorcentajeDescuento
        txtDependientes.Text = Empleados.Dependientes
        lstReligion.Text = Empleados.Religion
        txtUMF.Text = Empleados.UMF
        txtClabeInterbancaria.Text = Empleados.ClabeInterbancaria
        txtCorreoElectronico.Text = Empleados.CorreoEelectronico
        Select Case Empleados.TipoRegimen
            Case "2"
                lstRegimen.Text = "2. Sueldos y salarios"
            Case "3"
                lstRegimen.Text = "3. Jubilados"
            Case "4"
                lstRegimen.Text = "4. Pensionados"
            Case "5"
                lstRegimen.Text = "5. Asimilados a salarios, Miembros de las sociedades Cooperativas de Producción"
            Case "6"
                lstRegimen.Text = "6. Asimilados a salarios, Integrantes de Sociedades y Asociaciones Civiles"
            Case "7"
                lstRegimen.Text = "7. Asimilados a salarios, Miembros de consejos directivos, de vigilancia, consultivos, honorarios a administradores, comisarios y gerentes generales"
            Case "8"
                lstRegimen.Text = "8. Asimilados a salarios, Actividad empresarial (comisionistas)"
            Case "9"
                lstRegimen.Text = "9. Asimilados a salarios, Honorarios asimilados a salarios"
            Case "10"
                lstRegimen.Text = "10. Asimilados a salarios, Ingresos acciones o titulos valor"
            Case Else
                lstRegimen.Text = "Seleccionar uno..."
        End Select



        'Imagen
        Dim Completo As String = ""
        Completo = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text

        Me.pbFoto.Image = Nothing
        Me.Text = "Informacion General de " & Completo
        Dim imagen As String = "\\aussvr2\CONTPAQ\CompacW\Empresas\FOTOS\" & UCase(Completo) & ".jpg"
        Try
            Me.pbFoto.Image = Image.FromFile(imagen)
        Catch ex As Exception
        End Try

        LimpiaCampos()


        cargaIncapacidades()
        cargaReportes()
        cargaAccidentes()
        cargagratificaciones()
        BuscaGafete()
        cargaVacaciones()
        cargaPermisos()
        CargaObservaciones()
        CargaInfonavit()
        CargaFonacot()
        CargaInfonavitOLD()
        CargaFonacotOLD()
        cargaOtros()

        txtLicencia.Text = BuscarStrDatoCitra("Licencias", "Licencia", "IdEmpleado=" & EmpleadoID)
        txtTarjeton.Text = BuscarStrDatoCitra("Capacitacion", "Tarjeton", "IdEmpleado=" & EmpleadoID & " and STATUS='ALTA'")
        If txtLicencia.Text <> "" Then
            txtTipoLicencia.Text = "B"
        Else
            txtTipoLicencia.Text = ""
        End If

        Try
            datVencimientoLicencia.Value = BuscarDateDatoCitra("Licencias", "Vigencia", "IdEmpleado=" & EmpleadoID)
        Catch ex As Exception

        End Try



        dgEdoCta.Rows.Clear()

        Dim fianza As Double = BuscarDblDatoCitra("Fianzas", "fianza", "idempleado=" & EmpleadoID)
        Me.txtFianza.Text = fianza
       
        
        'Buscar datos de baja
        Me.txtBajas.Text = BuscarStrDatoCitra("Bajas", "CausaBaja", "idempleado=" & EmpleadoID)
        txtFiniquito.Text = BuscarStrDatoCitra("Bajas", "Finiquito", "idempleado=" & EmpleadoID)

        If txtStatus.Text.Trim = "Baja" Then
            Dim fechaBaja1 As Date = BuscarDateDatoCitra("Bajas", "fechaBaja", "idempleado=" & EmpleadoID)
            Dim IDEMP As Integer = BuscarIntDatoCitra("Bajas", "IDempleado", "idempleado=" & EmpleadoID)
            If IDEMP = 0 Then
                fechaBaja1 = BuscarDateDatoCitra("Empleados", "fechaBaja", "idempleado=" & EmpleadoID)
                Me.txtBajas.Text = BuscarStrDatoCitra("Empleados", "CausaBaja", "idempleado=" & EmpleadoID)
            End If

            Me.datBaja1.Value = fechaBaja1
        End If
        Bloquear()
        Muestra_OcultaTabs()

    End Sub
    Sub DesbloquearCampos()
        txtNSS.Enabled = True
        txtCuentaPago.Enabled = True
        txtCuentaContPAQ.Enabled = True
        txtFianza.Enabled = True
        txtRFC.Enabled = True
        txtHomoclave.Enabled = True
        txtCURP.Enabled = True
        txtCURPF.Enabled = True
        txtFechaCURP.Enabled = True
        txtFechaRFC.Enabled = True

    End Sub
    Sub Bloquear()
        Dim Largo As Integer

        Largo = Len(txtNSS.Text)
        If Largo > 0 Then
            txtNSS.Enabled = False
        Else
            txtNSS.Enabled = True
        End If

        Largo = Len(txtCuentaPago.Text)
        If Largo > 0 Then
            txtCuentaPago.Enabled = False
        Else
            txtCuentaPago.Enabled = True
        End If

        Largo = Len(txtCuentaContPAQ.Text)
        If Largo > 0 Then
            txtCuentaContPAQ.Enabled = False
        Else
            txtCuentaContPAQ.Enabled = True
        End If

        If txtFianza.Text > 0 Then
            txtFianza.Enabled = False
        Else
            txtFianza.Enabled = True
        End If

        Largo = Len(txtRFC.Text)
        If Largo > 0 Then
            txtRFC.Enabled = False
        Else
            txtRFC.Enabled = True
        End If

        Largo = Len(txtHomoclave.Text)
        If Largo > 0 Then
            txtHomoclave.Enabled = False
        Else
            txtHomoclave.Enabled = True
        End If

        Largo = Len(txtCURP.Text)
        If Largo > 0 Then
            txtCURP.Enabled = False
        Else
            txtCURP.Enabled = True
        End If

        Largo = Len(txtCURPF.Text)
        If Largo > 0 Then
            txtCURPF.Enabled = False
        Else
            txtCURPF.Enabled = True
        End If

        txtFechaCURP.Enabled = False
        txtFechaRFC.Enabled = False

    End Sub
    Sub BuscaGafete()
        Dim id As Integer = BuscarIntDatoCitra("Gafetes", "idempleado", "idempleado=" & EmpleadoID)
        If id = 0 Then
            chGafete.Checked = False
            datVencimientoGafete.Enabled = False
        Else
            Dim fecha As Date = BuscarDateDatoCitra("Gafetes", "Vence", "IDEMPLEADO=" & EmpleadoID)
            chGafete.Checked = True
            datVencimientoGafete.Enabled = True
            datVencimientoGafete.Value = fecha
        End If
    End Sub
    Sub cargaReportes()
        Me.dgReporte.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT * From Reportes " & _
        " WHERE idempleado=" & EmpleadoID

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim Fecha As Date

        Do While rdBuscar.Read()
            Fecha = rdBuscar("fecha")
            Me.dgReporte.Rows.Add(rdBuscar("idReporte"), Fecha.ToShortDateString, rdBuscar("motivo").ToString.Trim, rdBuscar("resolucion").ToString.Trim)
        Loop

    End Sub
    Sub limpiaCamposNuevo()
        Me.txtCodigo.Clear()
        Me.txtDepartamento.Clear()
        Me.txtPuesto.Clear()
        Me.txtNombre.Clear()
        Me.txtPaterno.Clear()
        Me.txtMaterno.Clear()
        Me.txtSD.Clear()
        Me.txtSDI.Clear()
        Me.datIngreso.Value = Now()
        Me.txtCalle.Clear()
        Me.txtNumero.Clear()
        Me.txtSD.Clear()
        Me.txtFiniquito.Clear()
        txtObservacion.Clear()


        Me.txtColonia.Clear()
        Me.txtCiudad.Clear()
        Me.txtEstado.Clear()
        Me.txtTelefono.Clear()
        Me.txtCodigoPostal.Clear()
        Me.datNacimiento.Value = Now()
        Me.txtNacimiento.Clear()
        Me.lstEstadoCivil.Text = ""
        Me.lstSexo.Text = ""
        Me.txtRFC.Clear()
        Me.txtHomoclave.Clear()
        Me.txtCURP.Clear()
        Me.txtCURPF.Clear()
        Me.txtBajas.Clear()
        Me.datBaja1.Value = Now()
        Me.txtCuentaPago.Clear()
        Me.txtCuentaContPAQ.Clear()
        Me.txtLicencia.Clear()
        Me.datVencimientoLicencia.Value = Now()


    End Sub
    Sub LimpiaCampos()
        'Limpia campos de Imss
        txtFolio.Clear()
        datFechaInicio.Value = Now()
        datFechaFin.Value = Now()
        txtIdInca.Clear()
        txtIdInca.Text = (BuscarIntDatoCitra("Select MAX(IdIncapacidad) as Id FROM Incapacidades")) + 1

        'Limpia Campos de Infonavit y Fonacot
        txtBimestreInfonavit.Text = BuscarIntDatoCitra("PeriodoInfonavit", "Bimestre", "Status='Abierto'")
        txtMesFonacot.Text = BuscarIntDatoCitra("PeriodoFonacot", "Mes", "Status='Abierto'")
        txtMontoFonacot.Clear()
        txtMontoInfonavit.Clear()
        txtMontoFonacot.Text = Format(0, "###,###.#0")
        txtMontoInfonavit.Text = Format(0, "###,###.#0")

        'Limpia Campos de Reportes
        datReporte.Value = Now()
        txtMotivo.Clear()
        txtIdRepo.Clear()
        txtResolucion.Clear()
        Me.txtIdRepo.Text = (BuscarIntDatoCitra("SELECT MAX(IdReporte) as Id FROM Reportes ")) + 1

        'Limpia campos de observaciones
        datObservac.Value = Now()
        txtObservacion.Clear()


    End Sub
    Private Sub txtIDEmpleado_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtIDEmpleado.TextChanged
        'Actualizar()

    End Sub

    Private Sub lstMotivo_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lstMotivo.SelectedIndexChanged
        If Me.lstMotivo.Text = "Riesgo de Trabajo" Then
            Me.lstMotivo2.Visible = True
            Me.lblMot.Visible = True
            Me.lstMotivo2.Text = ""
        Else
            Me.lstMotivo2.Visible = False
            Me.lblMot.Visible = False
            Me.lstMotivo2.Text = ""
        End If
    End Sub

    Private Sub txtDias_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtDias.TextChanged
        datFechaFin.Value = datFechaInicio.Value.AddDays(txtDias.Text - 1)
    End Sub

    Private Sub btnAbrir_Click(sender As System.Object, e As System.EventArgs) Handles btnAbrir.Click
        If Me.txtFolio.Text = "" Then
            MsgBox("Debes indicar el folio de la incapacidad", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtNSS.Text = "" Then
            MsgBox("Debes indicar el numero de afiliación del empleado", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.lstMotivo.Text = "" Then
            MsgBox("Debes indicar el motivo de la incapacidad", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtDias.Text = "" Then
            MsgBox("Debes indicar el numero de dias de la incapacidad", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        Incapacidad.idIncapacidad = Me.txtIdInca.Text
        Incapacidad.Folio = 0
        Incapacidad.Serie = Me.txtFolio.Text
        Incapacidad.IDEmpleado = EmpleadoID
        Incapacidad.Nombre = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        Incapacidad.IMSS = Me.txtNSS.Text
        Incapacidad.Motivo = Me.lstMotivo.Text
        Incapacidad.Tipo = Me.lstMotivo2.Text
        Incapacidad.FechaInicio = Me.datFechaInicio.Value
        Incapacidad.Dias = Me.txtDias.Text
        Incapacidad.FechaFin = Me.datFechaFin.Value
        Incapacidad.Reportado = "No"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "SELECT FechaFin From Incapacidades " & _
        " WHERE idempleado=" & EmpleadoID & " order by FechaFin"

        Dim rdBuscar As SqlDataReader

        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader
        Dim fechaanterior As Date


        Do While rdBuscar.Read()
            fechaanterior = rdBuscar("FechaFin")
        Loop
        fechaanterior = fechaanterior.AddDays(1)
        fechaanterior = DateSerial(Year(fechaanterior), Month(fechaanterior), DateAndTime.Day(fechaanterior))
        Dim nuevofecha As Date = Me.datFechaInicio.Value
        nuevofecha = DateSerial(Year(nuevofecha), Month(nuevofecha), DateAndTime.Day(nuevofecha))
        If nuevofecha = fechaanterior Then
            Incapacidad.Descripcion = "Subsecuente"
        Else
            Incapacidad.Descripcion = "Inicial"
        End If

        Incapacidad.Guardar()
        Me.txtFolio.Clear()
        Me.lstMotivo.Text = ""
        Me.lstMotivo2.Text = ""
        Me.datFechaInicio.Value = Now()
        Me.datFechaFin.Value = Now()
        Me.txtDias.Text = 0
        Me.txtIdInca.Clear()
        Me.lstMotivo2.Visible = False
        Me.lstMotivo2.Visible = False

        cargaIncapacidades()
        Me.txtIdInca.Text = (BuscarIntDatoCitra("Select MAX(IdIncapacidad) as Id FROM Incapacidades")) + 1
        Me.datFechaFin.Value = Now()
        Me.datFechaInicio.Value = Now()
        Me.txtDias.Text = 0
    End Sub

   

    Private Sub RadButton2_Click(sender As System.Object, e As System.EventArgs) Handles RadButton2.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Incapacidades de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeIncapacidades()

    End Sub
    Sub ImprimeIncapacidades()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 8
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Folio"
        wb.SHEETS(1).cells(rng, 3).value = "Motivo"
        wb.SHEETS(1).cells(rng, 4).value = "Tipo"
        wb.SHEETS(1).cells(rng, 5).value = "Fecha Inicio"
        wb.SHEETS(1).cells(rng, 6).value = "Dias"
        wb.SHEETS(1).cells(rng, 7).value = "Fecha Fin"
        wb.SHEETS(1).cells(rng, 8).value = "Descripción"
        wb.SHEETS(1).columns(2).columnwidth = 10
        wb.SHEETS(1).columns(3).columnwidth = 20
        wb.SHEETS(1).columns(4).columnwidth = 8
        'wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(5).columnwidth = 13
        wb.SHEETS(1).columns(6).columnwidth = 8
        wb.SHEETS(1).columns(7).columnwidth = 13
        wb.SHEETS(1).columns(8).columnwidth = 20

        rng = rng + 1
        For i = 0 To dgIncapacidades.Rows.Count - 1
            For j = 2 To 8
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgIncapacidades.Rows(i).Cells(1).Value.ToString.Trim
            wb.SHEETS(1).cells(rng, 3).value = dgIncapacidades.Rows(i).Cells(2).Value.ToString.Trim
            wb.SHEETS(1).cells(rng, 4).value = dgIncapacidades.Rows(i).Cells(3).Value.ToString.Trim
            wb.SHEETS(1).cells(rng, 5).value = dgIncapacidades.Rows(i).Cells(4).Value
            wb.SHEETS(1).cells(rng, 6).value = dgIncapacidades.Rows(i).Cells(5).Value
            wb.SHEETS(1).cells(rng, 7).value = dgIncapacidades.Rows(i).Cells(6).Value
            wb.SHEETS(1).cells(rng, 8).value = dgIncapacidades.Rows(i).Cells(7).Value.ToString.Trim
            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Incapacidades de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696

    End Sub

    Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
        Close()

    End Sub

    Private Sub ToolStripButton3_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton3.Click
        cont2 = cont2 + 1
        If ((valorRowSelect.Index + cont) - (cont2)) < 0 Then
            MsgBox("No hay mas registros para mostrar en el filtro", MsgBoxStyle.Exclamation, "Aviso")
            cont2 = cont2 - 1
            Exit Sub
        End If
        EmpleadoID = frmModuloEmpleados.dgEmpleados.Rows((valorRowSelect.Index + cont) - (cont2)).Cells(0).Value.ToString.Trim
        txtIDEmpleado.Text = EmpleadoID
        Actualizar()
    End Sub

    Private Sub ToolStripButton2_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton2.Click
        cont = cont + 1
        If cont - cont2 > limite Then
            MsgBox("No hay mas registros para mostrar en el filtro", MsgBoxStyle.Exclamation, "Aviso")
            cont = cont - 1
            Exit Sub
        End If
        EmpleadoID = frmModuloEmpleados.dgEmpleados.Rows((valorRowSelect.Index) + cont - cont2).Cells(0).Value.ToString.Trim
        txtIDEmpleado.Text = EmpleadoID
        Actualizar()

    End Sub

    Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
        If txtBimestreInfonavit.Text = "" Then
            MsgBox("Debes indicar el bimestre de infonavit", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtBimestreInfonavit.Text = 0 Then
            MsgBox("0 es un numero invalido para el bimestre", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        Dim Periodo As Integer = BuscarIntDatoCitra("PeriodoInfonavit", "Bimestre", "Status='Abierto'")
        If txtBimestreInfonavit.Text <> Periodo Then
            MsgBox("El bimestre indicado no corresponde con el bimestre actual", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If txtMontoInfonavit.Text = "" Then
            MsgBox("Debes indicar el monto a descontar en el bimestre", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtMontoInfonavit.Text = 0 Then
            MsgBox("0 es una cantidad incorrecta", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        CInfonavit.IdCargoInfonavit = (BuscarIntDatoCitra("Select MAX(IdCargoInfonavit) as Id FROM CargosInfonavit")) + 1
        CInfonavit.IdEmpleado = txtIDEmpleado.Text
        CInfonavit.Monto = txtMontoInfonavit.Text
        CInfonavit.Bimestre = txtBimestreInfonavit.Text
        CInfonavit.Anio = BuscarIntDatoCitra("PeriodoInfonavit", "Anio", "Status='Abierto'")
        CInfonavit.Fecha = datFechaInfonavit.Value
        CInfonavit.Insertar()
        CargaInfonavit()

        datFechaInfonavit.Value = Now()
        txtMontoInfonavit.Clear()
    End Sub

    Private Sub RadButton3_Click(sender As System.Object, e As System.EventArgs) Handles RadButton3.Click
        If txtMesFonacot.Text = "" Then
            MsgBox("Debes indicar el periodo de Fonacot", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtMesFonacot.Text = 0 Then
            MsgBox("0 es un numero invalido para el periodo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        Dim Periodo As Integer = BuscarIntDatoCitra("PeriodoFonacot", "Mes", "Status='Abierto'")
        If txtMesFonacot.Text <> Periodo Then
            MsgBox("El periodo indicado no corresponde con el periodo actual", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If txtMontoFonacot.Text = "" Then
            MsgBox("Debes indicar el monto a descontar en el periodo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtMontoFonacot.Text = 0 Then
            MsgBox("0 es una cantidad incorrecta", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If


        CFonacot.IdCargoFonacot = (BuscarIntDatoCitra("Select MAX(IdCargoFonacot) as Id FROM CargosFonacot")) + 1
        CFonacot.IdEmpleado = txtIDEmpleado.Text
        CFonacot.Monto = txtMontoFonacot.Text
        CFonacot.Mes = txtMesFonacot.Text
        CFonacot.Anio = BuscarIntDatoCitra("PeriodoFonacot", "Anio", "Status='Abierto'")
        CFonacot.Fecha = datFechaFonacot.Value
        CFonacot.Insertar()
        CargaFonacot()

        datFechaFonacot.Value = Now()
        txtMontoFonacot.Clear()
    End Sub

    Private Sub RadButton21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton21.Click
        frmInfonavit.ShowDialog()

    End Sub

    Private Sub RadButton20_Click(sender As System.Object, e As System.EventArgs) Handles RadButton20.Click
        frmFonacot.ShowDialog()

    End Sub

    Private Sub RadButton16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton16.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Infonavit de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeINFONAVIT()
    End Sub
    Sub ImprimeINFONAVIT()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Original"
        wb.SHEETS(1).cells(rng, 4).value = "Nuevo"
        wb.SHEETS(1).cells(rng, 5).value = "Observaciones"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 10
        wb.SHEETS(1).columns(4).columnwidth = 10
        wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(5).columnwidth = 40

        rng = rng + 1
        For i = 0 To dgInfonavit.Rows.Count - 1
            For j = 2 To 5
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgInfonavit.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgInfonavit.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgInfonavit.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgInfonavit.Rows(i).Cells(4).Value.ToString.Trim

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Infonavit de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696

    End Sub
    Sub ImprimeFONACOT()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Original"
        wb.SHEETS(1).cells(rng, 4).value = "Nuevo"
        wb.SHEETS(1).cells(rng, 5).value = "Observaciones"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 10
        wb.SHEETS(1).columns(4).columnwidth = 10
        wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(5).columnwidth = 40

        rng = rng + 1
        For i = 0 To dgFonacot.Rows.Count - 1
            For j = 2 To 5
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgFonacot.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgFonacot.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgFonacot.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgFonacot.Rows(i).Cells(4).Value.ToString.Trim

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Fonacot de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696

    End Sub

    Private Sub RadButton15_Click(sender As System.Object, e As System.EventArgs) Handles RadButton15.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Fonacot de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeFONACOT()

    End Sub

    Private Sub RadButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton7.Click
        If Me.txtMotivo.Text = "" Then
            MsgBox("Debes indicad el motivo del reporte", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If Me.txtResolucion.Text = "" Then
            MsgBox("Debes indicad la resolución del reporte", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        Repo.idempleado = EmpleadoID
        Repo.idReporte = Me.txtIdRepo.Text
        Repo.idConsecutivo = BuscarIntDatoCitra("SELECT MAX(IdReporte) as Id FROM Reportes WHERE IdEmpleado=" & EmpleadoID)
        Repo.fecha = Me.datReporte.Value
        Repo.Motivo = Me.txtMotivo.Text
        Repo.Resolucion = Me.txtResolucion.Text
        Repo.Guardar()
        Me.datReporte.Value = Now()
        Me.txtMotivo.Clear()
        Me.txtResolucion.Clear()
        Me.txtIdRepo.Text = (BuscarIntDatoCitra("SELECT MAX(IdReporte) as Id FROM Reportes ")) + 1
        cargaReportes()
    End Sub
    Sub ImprimeReportes()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 4
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Motivo"
        wb.SHEETS(1).cells(rng, 4).value = "Resolucion"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 80
        wb.SHEETS(1).columns(4).columnwidth = 80
        'wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        'wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        
        rng = rng + 1
        For i = 0 To dgReporte.Rows.Count - 1
            For j = 2 To 5
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgReporte.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgReporte.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgReporte.Rows(i).Cells(3).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Reportes de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton6_Click(sender As System.Object, e As System.EventArgs) Handles RadButton6.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Reportes de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeReportes()

    End Sub

    Private Sub RadMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles RadMenuItem1.Click
        frmAccidentes.ShowDialog()

    End Sub

    Private Sub RadMenuItem2_Click(sender As System.Object, e As System.EventArgs) Handles RadMenuItem2.Click
        frmIncidencias.ShowDialog()

    End Sub
    Sub ImprimeAccidentes()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 9
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Lugar"
        wb.SHEETS(1).cells(rng, 4).value = "Tipo"
        wb.SHEETS(1).cells(rng, 5).value = "Autobus"
        wb.SHEETS(1).cells(rng, 6).value = "Motivo"
        wb.SHEETS(1).cells(rng, 7).value = "Severidad"
        wb.SHEETS(1).cells(rng, 8).value = "Monto"
        wb.SHEETS(1).cells(rng, 9).value = "Cobro"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 50
        wb.SHEETS(1).columns(4).columnwidth = 20
        wb.SHEETS(1).columns(5).columnwidth = 15
        wb.SHEETS(1).columns(6).columnwidth = 50
        wb.SHEETS(1).columns(7).columnwidth = 20
        wb.SHEETS(1).columns(8).columnwidth = 13
        wb.SHEETS(1).columns(9).columnwidth = 13
        wb.SHEETS(1).columns(8).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgIncidente.Rows.Count - 1
            For j = 2 To 9
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgIncidente.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgIncidente.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgIncidente.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgIncidente.Rows(i).Cells(4).Value
            wb.SHEETS(1).cells(rng, 6).value = dgIncidente.Rows(i).Cells(5).Value
            wb.SHEETS(1).cells(rng, 7).value = dgIncidente.Rows(i).Cells(6).Value
            wb.SHEETS(1).cells(rng, 8).value = dgIncidente.Rows(i).Cells(7).Value
            wb.SHEETS(1).cells(rng, 9).value = dgIncidente.Rows(i).Cells(8).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Accidentes de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton10_Click(sender As System.Object, e As System.EventArgs) Handles RadButton10.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Accidentes de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeAccidentes()
    End Sub
    Private Sub RadButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton8.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Gratificaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeGratificaciones()
    End Sub
    Sub ImprimeGratificaciones()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 6
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Tipo"
        wb.SHEETS(1).cells(rng, 4).value = "Monto/Horas"
        wb.SHEETS(1).cells(rng, 5).value = "Observaciones"
        wb.SHEETS(1).cells(rng, 6).value = "Motivo"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 15
        wb.SHEETS(1).columns(4).columnwidth = 15
        wb.SHEETS(1).columns(5).columnwidth = 30
        wb.SHEETS(1).columns(6).columnwidth = 30
        'wb.SHEETS(1).columns(8).NumberFormat = "#,##0.0"
        'wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgGratificacion.Rows.Count - 1
            For j = 2 To 6
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgGratificacion.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgGratificacion.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgGratificacion.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgGratificacion.Rows(i).Cells(4).Value
            wb.SHEETS(1).cells(rng, 6).value = dgGratificacion.Rows(i).Cells(5).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Gratificaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton9_Click(sender As System.Object, e As System.EventArgs) Handles RadButton9.Click
        frmGratificaciones.ShowDialog()

    End Sub

    Private Sub RadButton12_Click(sender As System.Object, e As System.EventArgs) Handles RadButton12.Click
        frmVacaciones.ShowDialog()

    End Sub

    Private Sub RadButton14_Click(sender As System.Object, e As System.EventArgs) Handles RadButton14.Click
        frmPermisos.ShowDialog()
    End Sub

    Private Sub RadButton11_Click(sender As System.Object, e As System.EventArgs) Handles RadButton11.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Vacaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeVacaciones()
    End Sub
    Sub ImprimeVacaciones()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 7
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha Inicial"
        wb.SHEETS(1).cells(rng, 3).value = "Fecha Final"
        wb.SHEETS(1).cells(rng, 4).value = "Periodo"
        wb.SHEETS(1).cells(rng, 5).value = "Del"
        wb.SHEETS(1).cells(rng, 6).value = "Al"
        wb.SHEETS(1).cells(rng, 7).value = "Observaciones"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 12
        wb.SHEETS(1).columns(4).columnwidth = 20
        wb.SHEETS(1).columns(5).columnwidth = 12
        wb.SHEETS(1).columns(6).columnwidth = 12
        wb.SHEETS(1).columns(7).columnwidth = 40
        'wb.SHEETS(1).columns(8).NumberFormat = "#,##0.0"
        'wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgVacacion.Rows.Count - 1
            For j = 2 To 7
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgVacacion.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgVacacion.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgVacacion.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgVacacion.Rows(i).Cells(4).Value
            wb.SHEETS(1).cells(rng, 6).value = dgVacacion.Rows(i).Cells(5).Value
            wb.SHEETS(1).cells(rng, 7).value = dgVacacion.Rows(i).Cells(6).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Vacaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub
    Sub ImprimePermisos()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Dia"
        wb.SHEETS(1).cells(rng, 3).value = "Horario"
        wb.SHEETS(1).cells(rng, 4).value = "Tipo"
        wb.SHEETS(1).cells(rng, 5).value = "Observaciones"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 22
        wb.SHEETS(1).columns(4).columnwidth = 12
        wb.SHEETS(1).columns(5).columnwidth = 40
        'wb.SHEETS(1).columns(8).NumberFormat = "#,##0.0"
        'wb.SHEETS(1).columns(9).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgPermiso.Rows.Count - 1
            For j = 2 To 5
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgPermiso.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgPermiso.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgPermiso.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgPermiso.Rows(i).Cells(4).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Permisos de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton13_Click(sender As System.Object, e As System.EventArgs) Handles RadButton13.Click
        Bitacora.RegistraActividad("Imprimio el Historial de Permisos de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimePermisos()
    End Sub
    Sub cargaAdeudos()
        lstConcepto.Items.Clear()

        Dim cnconn As New SqlConnection
        cnconn.ConnectionString = CitraConnection

        Dim strSql As String = "Select Nombre FROM Adeudos WHERE IDADEUDO>4 and Aplicacion=0 ORDER BY NOMBRE"

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnconn
        cmdBuscar.CommandText = strSql

        Dim rdBuscar As SqlDataReader
        cnconn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            lstConcepto.Items.Add(rdBuscar("Nombre").ToString.Trim)
        Loop
    End Sub
    Private Sub lstConcepto_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstConcepto.SelectedIndexChanged
        EstadoCuenta()
    End Sub
    Sub EstadoCuenta()
        dgEdoCta.Rows.Clear()

        Dim cnconn As New SqlConnection
        cnconn.ConnectionString = CitraConnection

        Dim idAdeudo As Integer = BuscarIntDatoCitra("ADEUDOS", "IDADEUDO", "NOMBRE='" & lstConcepto.Text.Trim & "'")

        Dim strSql As String = "Select * FROM Movimientos Where IdEmpleado=" & txtIDEmpleado.Text & " AND IdAdeudo=" & idAdeudo & " ORDER BY IdMovimiento,Fecha,Tipo"

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnconn
        cmdBuscar.CommandText = strSql

        Dim rdBuscar As SqlDataReader
        cnconn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim Saldo As Double = 0
        Dim Tipo As Integer = 0
        Dim Cargo As Double = 0
        Dim Abono As Double = 0
        Dim fecha As Date

        Do While rdBuscar.Read()
            Tipo = rdBuscar("Tipo")
            If Tipo = 0 Then
                Cargo = rdBuscar("Monto")
                Abono = 0
            Else
                Abono = rdBuscar("Monto")
                Cargo = 0
            End If
            Saldo = Saldo + Cargo - Abono
            fecha = rdBuscar("fecha")
            dgEdoCta.Rows.Add(rdBuscar("IdMovimiento"), fecha.ToShortDateString, Cargo, Abono, Saldo)
        Loop
    End Sub

    Private Sub RadButton5_Click(sender As System.Object, e As System.EventArgs) Handles RadButton5.Click
        Bitacora.RegistraActividad("Imprimio un estado de cuenta de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeEstadoCuenta()
    End Sub
    Sub ImprimeEstadoCuenta()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Cargo"
        wb.SHEETS(1).cells(rng, 4).value = "Abono"
        wb.SHEETS(1).cells(rng, 5).value = "Saldo"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 12
        wb.SHEETS(1).columns(4).columnwidth = 12
        wb.SHEETS(1).columns(5).columnwidth = 12
        wb.SHEETS(1).columns(3).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(5).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgEdoCta.Rows.Count - 1
            For j = 2 To 5
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgEdoCta.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgEdoCta.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgEdoCta.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgEdoCta.Rows(i).Cells(4).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Estado de cuenta de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim & " del Concepto: " & lstConcepto.Text
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton4_Click(sender As System.Object, e As System.EventArgs) Handles RadButton4.Click
        If lstConcepto.Text = "" Then
            MsgBox("Debes indicar un concepto para el cargo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If txtCargo.Text = "" Then
            MsgBox("Debes de indicar el monto de cargo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        If txtCargo.Text = 0 Then
            MsgBox("0 no es un valor valido para el cargo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If

        Mov.IdMovimiento = (BuscarIntDatoCitra("SELECT MAX(IdMovimiento) as Id FROM Movimientos")) + 1
        Mov.IDAdeudo = BuscarIntDatoCitra("Adeudos", "IDADEUDO", "NOMBRE='" & lstConcepto.Text.Trim & "'")
        Mov.IdEmpleado = txtIDEmpleado.Text
        Mov.IdNomina = 0
        Mov.Fecha = datFecha.Value
        Mov.Monto = txtCargo.Text
        Mov.Tipo = 0
        Mov.Insertar()

        Bitacora.RegistraActividad("Registro un Cargo a " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)

        EstadoCuenta()
        txtCargo.Clear()
        datFecha.Value = Now()
    End Sub


    Private Sub RadButton23_Click(sender As System.Object, e As System.EventArgs) Handles RadButton23.Click
        frmOtroCargos.ShowDialog()
    End Sub

    Sub ImprimeOtrosCargos()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 6
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Motivo"
        wb.SHEETS(1).cells(rng, 4).value = "Monto"
        wb.SHEETS(1).cells(rng, 5).value = "Tiempo a descontar"
        wb.SHEETS(1).cells(rng, 6).value = "Descuentos de:"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 40
        wb.SHEETS(1).columns(4).columnwidth = 12
        wb.SHEETS(1).columns(5).columnwidth = 12
        wb.SHEETS(1).columns(6).columnwidth = 12
        wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        wb.SHEETS(1).columns(6).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgOtros.Rows.Count - 1
            For j = 2 To 6
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgOtros.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgOtros.Rows(i).Cells(2).Value
            wb.SHEETS(1).cells(rng, 4).value = dgOtros.Rows(i).Cells(3).Value
            wb.SHEETS(1).cells(rng, 5).value = dgOtros.Rows(i).Cells(4).Value
            wb.SHEETS(1).cells(rng, 6).value = dgOtros.Rows(i).Cells(5).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Cargos de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

    Private Sub RadButton22_Click(sender As System.Object, e As System.EventArgs) Handles RadButton22.Click
        Bitacora.RegistraActividad("Imprimio historial de cargos de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeOtrosCargos()
    End Sub

    Private Sub RadButton18_Click(sender As System.Object, e As System.EventArgs) Handles RadButton18.Click
        'Guarda observacion
        Obs.idObservacion = (BuscarIntDatoCitra("SELECT MAX(IdObservacion) as Id FROM Observaciones")) + 1
        obs.idempleado = EmpleadoID
        Obs.Observacion = txtObservacion.Text.Trim
        obs.Capturo = UsuarioActivo
        obs.Reportado = "No"
        obs.Fecha = datObservac.Value
        obs.Insertar()

        'Actividad
        Bitacora.RegistraActividad("Registro observaciones a " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        CargaObservaciones()
    End Sub

    Private Sub RadButton17_Click(sender As System.Object, e As System.EventArgs) Handles RadButton17.Click
        Bitacora.RegistraActividad("Imprimio historial de observaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim)
        ImprimeObservaciones()
    End Sub
    Sub ImprimeObservaciones()
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook


        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim rng As Integer = 5

        For i = 2 To 3
            wb.SHEETS(1).cells(rng, i).FONT.name = "Segoe UI Light"
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).CELLS(rng, i).HorizontalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).VerticalAlignment = -4108
            wb.SHEETS(1).CELLS(rng, i).WrapText = True
            wb.SHEETS(1).CELLS(rng, i).Orientation = 0
            wb.SHEETS(1).CELLS(rng, i).AddIndent = False
            wb.SHEETS(1).CELLS(rng, i).IndentLevel = 0
            wb.SHEETS(1).CELLS(rng, i).ShrinkToFit = False
            wb.SHEETS(1).CELLS(rng, i).MergeCells = False
            wb.SHEETS(1).CELLS(rng, i).ReadingOrder = -5002
        Next
        wb.SHEETS(1).cells(rng, 2).value = "Fecha"
        wb.SHEETS(1).cells(rng, 3).value = "Observacion"
        wb.SHEETS(1).columns(2).columnwidth = 12
        wb.SHEETS(1).columns(3).columnwidth = 40
        'wb.SHEETS(1).columns(4).NumberFormat = "#,##0.0"
        'wb.SHEETS(1).columns(6).NumberFormat = "#,##0.0"

        rng = rng + 1
        For i = 0 To dgObservaciones.Rows.Count - 1
            For j = 2 To 6
                wb.SHEETS(1).cells(rng, j).FONT.name = "Segoe UI Light"

            Next
            wb.SHEETS(1).cells(rng, 2).value = dgObservaciones.Rows(i).Cells(1).Value
            wb.SHEETS(1).cells(rng, 3).value = dgObservaciones.Rows(i).Cells(2).Value

            rng = rng + 1
        Next

        wb.SHEETS(1).cells(1, 2).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 2).FONT.SIZE = 20
        wb.SHEETS(1).cells(1, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(2, 2).value = "Historial de Observaciones de " & txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        wb.SHEETS(1).cells(2, 2).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 2).FONT.name = "Segoe UI Light"
        wb.SHEETS(1).cells(3, 2).value = "Impreso el " & Now().Day & "-" & Now().Month & "-" & Now().Year & " por " & UsuarioActivo
        wb.SHEETS(1).cells(3, 3).FONT.SIZE = 12
        wb.SHEETS(1).cells(3, 3).FONT.name = "Segoe UI Light"

        wb.SHEETS(1).cells(1, 1).value = ""
        wb.SHEETS(1).columns(1).columnwidth = 3
        wb.sheets(1).cells(1, 1).interior.color = 15773696
        wb.sheets(1).cells(2, 1).interior.color = 15773696
    End Sub

  
    Private Sub RadButton19_Click(sender As System.Object, e As System.EventArgs) Handles RadButton19.Click
        Call SetSqlCitra("Update Bajas SET Finiquito='" & Me.txtFiniquito.Text.Trim & "' where idempleado=" & Me.txtIDEmpleado.Text.Trim)
        MsgBox("Actualización Éxitosa", MsgBoxStyle.Information, "Aviso")
    End Sub

    Private Sub ToolStripButton5_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton5.Click
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        Guardar()
        Bitacora.RegistraActividad("Guardó el registro de " & Completo)
    End Sub
    Sub Guardar()
        If Me.txtNombre.Text = "" Then
            MsgBox("Debes indicar el nombre del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtCodigo.Text = "" Then
            MsgBox("Debes indicar el codigo del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtPaterno.Text = "" Then
            MsgBox("Debes indicar el apellido paterno del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtMaterno.Text = "" Then
            MsgBox("Debes indicar el apellido materno del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtDepartamento.Text = "" Then
            MsgBox("Debes indicar el departamento del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtPuesto.Text = "" Then
            MsgBox("Debes indicar el puesto del empleado", MsgBoxStyle.Exclamation, " Aviso")
            Exit Sub
        End If
        If Me.txtCodigoPostal.Text = "" Then
            Me.txtCodigoPostal.Text = 0
        End If

        If EmpleadoNuevo = True Then
            'Primero verifica que la mascarilla del codigo sea correcta
            Dim Mascarilla As String = BuscarStrDatoNominas("Select MascarillaCodigo From Nom10000")
            Dim CaracteresMascarilla As Integer = Len(Mascarilla.Trim)
            Dim CaracteresCodigo As Integer = Len(txtCodigo.Text.Trim)

            If CaracteresCodigo < CaracteresMascarilla Then
                MsgBox("Faltan caracteres en el Codigo del Empleado", MsgBoxStyle.Exclamation, "Aviso")
                Exit Sub
            ElseIf CaracteresCodigo > CaracteresMascarilla Then
                MsgBox("Sobran caracteres en el Codigo del Empleado", MsgBoxStyle.Exclamation, "Aviso")
                Exit Sub
            Else
                'Si la mascarilla es correcta, verifica que el codigo ya exista en NomiPAQ
                Dim CodigoNomipaq As String = BuscarStrDatoNominas("Nom10001", "CodigoEmpleado", "CodigoEmpleado='" & txtCodigo.Text.Trim & "'")
                'Si el codigo ya existe ahora verificar que el nombre corresponda al asignado en nomipaq y si no existe mandar aviso
                If CodigoNomipaq.Trim <> "" Then
                    'Verifica Nombre
                    Dim NombreLargo As String = BuscarStrDatoNominas("Nom10001", "NombreLargo", "CodigoEmpleado='" & txtCodigo.Text.Trim & "'")
                    If UCase(NombreLargo.Trim) <> UCase(txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim) Then
                        MsgBox("El nombre indicado no corresponde con el asignado al codigo en NomiPAQ", MsgBoxStyle.Exclamation, "Aviso")
                        Exit Sub
                    End If
                Else
                    MsgBox("El codigo indicado no existe en NomiPAQ", MsgBoxStyle.Exclamation, "Aviso")
                    Exit Sub
                End If

            End If
            'GuardaLicencia
            lice.idempleado = EmpleadoID
            lice.Licencia = Me.txtLicencia.Text
            lice.Tipo = "B"
            lice.Vigencia = Me.datVencimientoLicencia.Value
            lice.Guardar()

            'Guarda Gafeta
            If chGafete.Checked = True Then
                insertaGafete()
            Else
                Call SetSqlCitra("DELETE FROM Gafetes WHERE IDEMPLEADO=" & EmpleadoID)
            End If

            'Guarda Fianza
            Dim FZA As Double
            fianzas.idempleado = EmpleadoID
            If Me.txtFianza.Text = "" Then
                Me.txtFianza.Text = 0

            End If
            FZA = Me.txtFianza.Text
            If FZA > 0 Then
                Fianzas.Fianza = Me.txtFianza.Text
                fianzas.fecha = Now()
                fianzas.Capturo = UsuarioActivo
                fianzas.Reportado = "No"
                fianzas.Guardar()
            End If

            Dim ALTA As New clsAltas
            ALTA.idAlta = (BuscarIntDatoCitra("SELECT MAX(IdAlta) as Id FROM Altas")) + 1
            ALTA.IdEmpleado = txtIDEmpleado.Text
            ALTA.Reportado = "No"
            ALTA.Usuario = UsuarioActivo
            ALTA.Insertar()

            gatter()
            Empleados.Guardar()
            Empleados.ActualizarNomiPAQ()

            Bitacora.RegistraActividad("Registró la alta de " & Empleados.NombreCompleto)

            MsgBox("Guardado Exitoso", MsgBoxStyle.Information, "Aviso")
            Me.Close()
        Else
            'GuardaLicencia
            lice.idempleado = EmpleadoID
            lice.Licencia = Me.txtLicencia.Text
            lice.Tipo = "B"
            Lice.Vigencia = Me.datVencimientoLicencia.Value
            lice.Guardar()

            'Guarda Gafeta
            If chGafete.Checked = True Then
                insertaGafete()
            Else
                Call SetSqlCitra("DELETE FROM Gafetes WHERE IDEMPLEADO=" & EmpleadoID)
            End If

            'Guarda Fianza
            Dim FZA As Double

            fianzas.idempleado = EmpleadoID
            If Me.txtFianza.Text.Trim = "" Then
                Me.txtFianza.Text = 0

            End If
            FZA = Me.txtFianza.Text
            If FZA > 0 Then
                Fianzas.Fianza = Me.txtFianza.Text
                fianzas.fecha = Now()
                fianzas.Capturo = UsuarioActivo
                fianzas.Reportado = "No"
                fianzas.Guardar()
            End If

            gatter()
            Empleados.Guardar()
            'Registra actividad
            Bitacora.RegistraActividad("Actualizó el registro de " & Empleados.NombreCompleto)
            Empleados.ActualizarNomiPAQ()
            Bloquear()

            MsgBox("El registro se ha actualizado correctamente", MsgBoxStyle.Information, "Aviso")
        End If
    End Sub
    Sub insertaGafete()
        Dim Gaf As New clsGafetes

        Dim fecha As Date = datVencimientoGafete.Value

        Dim id As Integer = BuscarIntDatoCitra("Gafetes", "idempleado", "idempleado=" & EmpleadoID)

        If id = 0 Then
            Gaf.idempleado = EmpleadoID
            Gaf.Vence = fecha
            Gaf.Insertar()

        Else
            Gaf.idempleado = EmpleadoID
            Gaf.Vence = fecha
            Gaf.Actualizar()

        End If
    End Sub
  
    Private Sub gatter()
        Dim departamento As String = Me.txtDepartamento.Text.Trim
        Dim puesto As String = Me.txtPuesto.Text.Trim
        Dim periodo As String = ""
        Dim turno As String = ""

        Empleados.IdDepartamento = BuscarIntDatoCitra("Departamentos", "IdDepartamento", "descripcion='" & departamento & "'")
        Empleados.IDPuesto = BuscarIntDatoCitra("Puestos", "IDPUESTO", "descripcion='" & puesto & "'")
        Empleados.IDPerdiodo = BuscarIntDatoNominas("NOM10001", "IDTipoPeriodo", "CodigoEmpleado='" & txtCodigo.Text.Trim & "'")
        Empleados.IDTurno = BuscarIntDatoNominas("NOM10001", "IdTurno", "CodigoEmpleado='" & txtCodigo.Text.Trim & "'")
        empleados.IDEmpleado = Me.txtIDEmpleado.Text
        Empleados.Codigo = Me.txtCodigo.Text.Trim

        empleados.Nombre = Me.txtNombre.Text
        Empleados.ApellidoPaterno = Me.txtPaterno.Text
        Empleados.ApellidoMaterno = Me.txtMaterno.Text
        Empleados.NombreCompleto = Me.txtPaterno.Text.Trim & " " & Me.txtMaterno.Text.Trim & " " & Me.txtNombre.Text.Trim

        Empleados.FechaNacimiento = Me.datNacimiento.Value
        Empleados.LugarNacimiento = Me.txtNacimiento.Text
        Dim estadoCivil As String = Me.lstEstadoCivil.Text
        Select Case estadoCivil
            Case "Casado(a)"
                Empleados.EstadoCivil = "C"
            Case "Soltero(a)"
                Empleados.EstadoCivil = "S"
            Case "Divorciado(a)"
                Empleados.EstadoCivil = "D"
            Case "Viudo(a)"
                Empleados.EstadoCivil = "V"
        End Select
        Dim sexo As String = Me.lstSexo.Text
        Select Case sexo
            Case "Masculino"
                empleados.Sexo = "M"
            Case "Femenino"
                empleados.Sexo = "F"
        End Select
        Empleados.CURP = Me.txtCURP.Text
        empleados.CURPF = Me.txtCURPF.Text
        Empleados.NSS = Me.txtNSS.Text
        empleados.RFC = Me.txtRFC.Text
        empleados.Homoclave = Me.txtHomoclave.Text
        empleados.CuentaPago = Me.txtCuentaPago.Text
        empleados.Sucursal = 0
        empleados.BancoPago = 0
        Dim estatus As String = txtStatus.Text.Trim

        Select Case estatus
            Case "Alta"
                Empleados.EstadoEmpleado = "A"
            Case "Baja"
                Empleados.EstadoEmpleado = "B"
            Case "Reingreso"
                Empleados.EstadoEmpleado = "R"
        End Select

        empleados.SD = Me.txtSD.Text
        Empleados.FechaSD = Me.datIngreso.Value
        empleados.SDI = Me.txtSDI.Text
        Empleados.FechaSDI = Me.datIngreso.Value
        Empleados.FechaAlta = Me.datIngreso.Value
        Empleados.CuentaCW = txtCuentaContPAQ.Text
        empleados.Telefono = Me.txtTelefono.Text
        Empleados.CodigoPostal = Me.txtCodigoPostal.Text.Trim
        Dim domi As String = Me.txtCalle.Text.Trim & ", " & Me.txtNumero.Text.Trim & "," & Me.txtColonia.Text.Trim
        empleados.Direccion = domi
        empleados.Poblacion = Me.txtCiudad.Text
        empleados.Estado = Me.txtEstado.Text
        empleados.FechaBaja = Now()
        empleados.CausaBaja = ""
        empleados.Celular = Me.txtCelular.Text
        Empleados.TelefonoRecados = Me.txtRecados.Text
        Empleados.Escolaridad = Me.lstEscolaridad.Text
        Empleados.FechaReingreso = Now()
        Empleados.PorcentajeDescuento = txtPorcentaje.Text
        Empleados.Dependientes = txtDependientes.Text
        Empleados.Religion = lstReligion.Text
        Empleados.UMF = txtUMF.Text
        Empleados.ClabeInterbancaria = txtClabeInterbancaria.Text
        Empleados.CorreoEelectronico = txtCorreoElectronico.Text

        Select Case lstRegimen.Text
            Case "2. Sueldos y salarios"
                Empleados.TipoRegimen = "2"
            Case "3. Jubilados"
                Empleados.TipoRegimen = "3"
            Case "4. Pensionados"
                Empleados.TipoRegimen = "4"
            Case "5. Asimilados a salarios, Miembros de las sociedades Cooperativas de Producción"
                Empleados.TipoRegimen = "5"
            Case "6. Asimilados a salarios, Integrantes de Sociedades y Asociaciones Civiles"
                Empleados.TipoRegimen = "6"
            Case "7. Asimilados a salarios, Miembros de consejos directivos, de vigilancia, consultivos, honorarios a administradores, comisarios y gerentes generales"
                Empleados.TipoRegimen = "7"
            Case "8. Asimilados a salarios, Actividad empresarial (comisionistas)"
                Empleados.TipoRegimen = "8"
            Case "9. Asimilados a salarios, Honorarios asimilados a salarios"
                Empleados.TipoRegimen = "9"
            Case "10. Asimilados a salarios, Ingresos acciones o titulos valor"
                Empleados.TipoRegimen = "10"
            Case Else
                Empleados.TipoRegimen = ""
        End Select


    End Sub
    Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Click

        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & " " & txtNombre.Text.Trim
        Guardar()
        Bitacora.RegistraActividad("Guardó el registro de " & Completo)

    End Sub

    Private Sub txtSD_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSD.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            txtPorcentaje.Focus()
            txtPorcentaje.SelectAll()
        End If
    End Sub

    Private Sub txtSD_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtSD.TextChanged
       

    End Sub

    Private Sub txtStatus_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtStatus.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            txtSD.Focus()
            txtSD.SelectAll()
        End If
    End Sub

    Private Sub txtStatus_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtStatus.TextChanged
        If Trim(Me.txtStatus.Text) = "Baja" Then
            txtStatus.BackColor = Color.Red
            TabPage12.Parent = TabControl1
            Dim finiquito As String = BuscarStrDatoCitra("Bajas", "Finiquito", "IDEmpleado=" & Me.txtIDEmpleado.Text.Trim)
            txtFiniquito.Text = finiquito
        ElseIf Trim(Me.txtStatus.Text) = "Alta" Then
            Me.txtStatus.BackColor = Color.Green
            TabPage12.Parent = Nothing
        Else
            Me.txtStatus.BackColor = Color.Blue
            TabPage12.Parent = Nothing
        End If
    End Sub
    Sub Baja()
        If Me.txtStatus.Text.Trim = "Baja" Then
            MsgBox("El empleado ya es baja", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        frmDarBaja.ShowDialog()
    End Sub

    Private Sub BajaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles BajaToolStripMenuItem.Click
        Baja()

    End Sub

    Private Sub CapacitacionesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CapacitacionesToolStripMenuItem.Click
        frmCapacitacion.ShowDialog()
    End Sub

    Private Sub UniformesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles UniformesToolStripMenuItem.Click
        frmUniformes.ShowDialog()
    End Sub


    Private Sub InternaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        frmEvaluacionInterna.ShowDialog()

    End Sub

    Private Sub IntegradaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        frmEvaluacionesFull.ShowDialog()
    End Sub

    Private Sub EliminarPermisoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarPermisoToolStripMenuItem.Click
        Dim registros As Integer = dgPermiso.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgPermiso.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Permisos", "Reportado", "idPermiso=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Permisos WHERE idPermiso=" & ID)
                    cargaPermisos()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de permisos de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Permisos WHERE idPermiso=" & ID)
                cargaPermisos()
                'Actividad
                cargaIncapacidades()
                Bitacora.RegistraActividad("Eliminó un registro de permisos de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminarObservacionToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarObservacionToolStripMenuItem.Click
        Dim registros As Integer = dgObservaciones.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgObservaciones.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Observaciones", "Reportado", "idObservacion=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Observaciones WHERE idObservacion=" & ID)
                    CargaObservaciones()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de observaciones de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Observaciones WHERE idObservacion=" & ID)
                CargaObservaciones()
                'Actividad
                cargaIncapacidades()
                 Bitacora.RegistraActividad("Eliminó un registro de observaciones de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub ElimiarIncapacidadToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ElimiarIncapacidadToolStripMenuItem.Click
        Dim registros As Integer = dgIncapacidades.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgIncapacidades.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Incapacidades", "Reportado", "idincapacidad=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Incapacidades WHERE idincapacidad=" & ID)
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de incapacidad de " & Completo)
                   
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Incapacidades WHERE idincapacidad=" & ID)
                cargaIncapacidades()
                'Actividad
                cargaIncapacidades()
                Bitacora.RegistraActividad("Eliminó un registro de incapacidad de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminarReporteToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarReporteToolStripMenuItem.Click
        Dim registros As Integer = dgReporte.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgReporte.CurrentRow.Cells(0).Value
            Call SetSqlCitra("DELETE FROM Reportes WHERE IDReporte=" & ID)
            cargaReportes()
            'Actividad
            cargaIncapacidades()
            Bitacora.RegistraActividad("Eliminó un registro de reportes de " & Completo)
            MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
        End If
    End Sub

    Private Sub EliminarIncidenteToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarIncidenteToolStripMenuItem.Click
        Dim registros As Integer = dgIncidente.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgIncidente.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Accidentes", "Reportado", "idAccidente=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Accidentes WHERE idAccidente=" & ID)
                    cargaAccidentes()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de incidentes de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Accidentes WHERE idAccidente=" & ID)
                cargaAccidentes()
                'Actividad
                cargaIncapacidades()
               Bitacora.RegistraActividad("Eliminó un registro de incidentes de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminaGratificaciónToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminaGratificaciónToolStripMenuItem.Click
        Dim registros As Integer = dgGratificacion.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgGratificacion.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Gratificaciones", "Notificado", "idGratificacion=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Gratificaciones WHERE idGratificacion=" & ID)
                    cargagratificaciones()
                    'Actividad
                    cargaIncapacidades()

                    Bitacora.RegistraActividad("Eliminó un registro de gratificaciones de " & completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Gratificaciones WHERE idGratificacion=" & ID)
                cargagratificaciones()
                'Actividad
                cargaIncapacidades()
               Bitacora.RegistraActividad("Eliminó un registro de gratificaciones de " & completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminarVacacionesToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarVacacionesToolStripMenuItem.Click
        Dim registros As Integer = dgVacacion.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgVacacion.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("Vacaciones", "Reportado", "idVacacion=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM Vacaciones WHERE idVacacion=" & ID)
                    cargaVacaciones()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de vacaciones de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM Vacaciones WHERE idVacacion=" & ID)
                cargaVacaciones()
                'Actividad
                cargaIncapacidades()
                Bitacora.RegistraActividad("Eliminó un registro de vacaciones de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminarInfonavitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarInfonavitToolStripMenuItem.Click
        Dim registros As Integer = dgInfonavit.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgInfonavit.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("InfonavitFonacot", "Reportado", "idRegistro=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM InfonavitFonacot WHERE idRegistro=" & ID)
                    cargaVacaciones()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de infonavit de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM InfonavitFonacot WHERE idRegistro=" & ID)
                CargaInfonavit()
                'Actividad
                Bitacora.RegistraActividad("Eliminó un registro de infonavit de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub EliminarFonacotToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles EliminarFonacotToolStripMenuItem.Click
        Dim registros As Integer = dgFonacot.Rows.Count
        If registros = 0 Then
            MsgBox("No existen registros para eliminar", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub

        End If
        Dim Resp As Integer = MsgBox("¿Deseas eliminar el registro seleccionado?", MsgBoxStyle.YesNo, "Aviso")
        Dim Completo As String = txtPaterno.Text.Trim & " " & txtMaterno.Text.Trim & "" & txtNombre.Text.Trim
        If Resp = 6 Then
            Dim ID As Integer = dgFonacot.CurrentRow.Cells(0).Value
            Dim reportado As String = BuscarStrDatoCitra("InfonavitFonacot", "Reportado", "idRegistro=" & ID)
            If reportado = "Si" Then
                Dim resp2 As Integer = MsgBox("El registro ya fue reportado a Nominas, al eliminarlo debere informar al responsable de nominas de su eliminación, ¿Continuar?", MsgBoxStyle.YesNo, "Aviso")
                If resp2 = 6 Then
                    Call SetSqlCitra("DELETE FROM InfonavitFonacot WHERE IdRegistro=" & ID)
                    cargaVacaciones()
                    'Actividad
                    cargaIncapacidades()
                    Bitacora.RegistraActividad("Eliminó un registro de fonacot de " & Completo)
                    MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
                End If
            Else
                Call SetSqlCitra("DELETE FROM InfonavitFonacot WHERE IdRegistro=" & ID)
                CargaFonacot()
                'Actividad
                Bitacora.RegistraActividad("Eliminó un registro de fonacot de " & Completo)
                MsgBox("El registro ha sido eliminado", MsgBoxStyle.Information, "Aviso")
            End If
        End If
    End Sub

    Private Sub btnDepto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDepto.Click
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(1)
        If frmCatalogosP.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogosP.Valor
            Me.txtDepartamento.Text = Trim(frmCatalogosP.dgCatalogos.Rows(strResult - 1).Cells(3).Value.ToString())
        End If
    End Sub

    Private Sub btnPuesto_Click(sender As System.Object, e As System.EventArgs) Handles btnPuesto.Click
        Dim lerror As Integer
        lerror = fDespliegaCatalogos(2)
        If frmCatalogosP.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogosP.Valor
            Me.txtPuesto.Text = Trim(frmCatalogosP.dgCatalogos.Rows(strResult - 1).Cells(3).Value.ToString())
        End If
    End Sub

    Private Sub NuevaToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NuevaToolStripMenuItem.Click
        txtCodigo.Enabled = True
        txtPaterno.Enabled = True
        txtMaterno.Enabled = True
        txtNombre.Enabled = True
        txtDepartamento.Enabled = True
        txtPuesto.Enabled = True
        btnDepto.Enabled = True
        btnPuesto.Enabled = True
        txtSD.Enabled = True
        txtSDI.Enabled = False
        txtFechaCURP.Enabled = False
        txtFechaRFC.Enabled = False

        LimpiaCampos()
        EmpleadoID = (BuscarIntDatoCitra("SELECT MAX(IdEmpleado) as IdEmpleado FROM Empleados")) + 1
        Me.txtIDEmpleado.Text = EmpleadoID
        Muestra_OcultaTabs()
        Actualizar()
        txtSD.Text = 0
        txtNumero.Clear()
        txtColonia.Clear()

        AccionesToolStripMenuItem.Visible = False
        AccionesToolStripMenuItem1.Visible = False
        InformesToolStripMenuItem.Visible = False
        ToolStripButton3.Visible = False
        ToolStripButton2.Visible = False

        Me.txtIDEmpleado.Enabled = False
        txtStatus.Text = "Alta"
        txtStatus.Enabled = True
        Me.pbFoto.Image = Nothing
        Me.lstEscolaridad.Visible = True
        Me.Label37.Visible = True
        Me.txtTarjeton.Enabled = False
        Me.RadDropDownButton3.Enabled = False

        TabPage2.Parent = Nothing
        TabPage3.Parent = Nothing
        TabPage4.Parent = Nothing
        TabPage5.Parent = Nothing
        TabPage6.Parent = Nothing
        TabPage7.Parent = Nothing
        TabPage8.Parent = Nothing
        TabPage9.Parent = Nothing
        TabPage10.Parent = Nothing
        TabPage11.Parent = Nothing
        TabPage12.Parent = Nothing

        chGafete.Checked = False
        datVencimientoGafete.Enabled = True

        txtCodigo.Focus()
        txtCodigo.SelectAll()

    End Sub

    Private Sub IndicarAdeudoToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles IndicarAdeudoToolStripMenuItem.Click
        frmCuentasUna.ShowDialog()

    End Sub
    Sub imprimetodas()
        Dim xl As Object
        Dim wb As Object
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer = 5

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim strSql As String = ""

        strSql = "SELECT M.IdAdeudo,Nombre,Fecha,Monto,Tipo " & _
                 "FROM Movimientos M INNER JOIN Adeudos A ON M.IdAdeudo=A.IdAdeudo " & _
                 "WHERE IdEmpleado=" & txtIDEmpleado.Text & " AND Aplicacion=0 ORDER BY M.IdAdeudo,Fecha"

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim Saldo As Double = 0
        Dim Cargos As Double = 0
        Dim Abonos As Double = 0
        Dim TotalCargos As Double = 0
        Dim TotalAbonos As Double = 0
        Dim SaldoTotal As Double = 0
        Dim IdAdeudo As Integer = 0
        Dim Primero As Boolean = True
        Dim tipo As Integer

        Do While rdBuscar.Read()
            If IdAdeudo <> rdBuscar("IdAdeudo") Then
                If Primero = False Then
                    wb.SHEETS(1).cells(rng, 2).value = "Totales"
                    wb.SHEETS(1).cells(rng, 3).value = Cargos
                    wb.SHEETS(1).cells(rng, 4).value = Abonos
                    wb.SHEETS(1).cells(rng, 5).value = Cargos - Abonos
                    For i = 2 To 5
                        wb.SHEETS(1).cells(rng, i).font.bold = True
                        wb.SHEETS(1).cells(rng, i).font.italic = True
                    Next
                    Cargos = 0
                    Abonos = 0
                    Saldo = 0
                    rng = rng + 1
                End If
                rng = rng + 1
                wb.SHEETS(1).cells(rng, 1).value = "Fecha"
                wb.SHEETS(1).cells(rng, 2).value = "Concepto"
                wb.SHEETS(1).cells(rng, 3).value = "Cargos"
                wb.SHEETS(1).cells(rng, 4).value = "Abonos"
                wb.SHEETS(1).cells(rng, 5).value = "Saldo"
                For i = 1 To 5
                    wb.SHEETS(1).cells(rng, i).font.bold = True
                Next
                rng = rng + 1
                Primero = False
            End If
            IdAdeudo = rdBuscar("IdAdeudo")
            tipo = rdBuscar("Tipo")
            If rdBuscar("Monto") > 0 Then
                wb.SHEETS(1).cells(rng, 1).value = rdBuscar("Fecha")
                If tipo = 0 Then
                    wb.SHEETS(1).cells(rng, 2).value = "Cargo de " & rdBuscar("Nombre").ToString.Trim
                    wb.SHEETS(1).cells(rng, 3).value = rdBuscar("Monto")
                    wb.SHEETS(1).cells(rng, 4).value = 0
                    Cargos = Cargos + rdBuscar("Monto")
                    TotalCargos = TotalCargos + rdBuscar("Monto")
                    Saldo = Saldo + rdBuscar("Monto")
                    SaldoTotal = SaldoTotal + rdBuscar("Monto")
                Else
                    wb.SHEETS(1).cells(rng, 2).value = "Abono de " & rdBuscar("Nombre").ToString.Trim
                    wb.SHEETS(1).cells(rng, 3).value = 0
                    wb.SHEETS(1).cells(rng, 4).value = rdBuscar("Monto")
                    Abonos = Abonos + rdBuscar("Monto")
                    TotalAbonos = TotalAbonos + rdBuscar("Monto")
                    Saldo = Saldo - rdBuscar("Monto")
                    SaldoTotal = SaldoTotal - rdBuscar("Monto")
                End If

                wb.SHEETS(1).cells(rng, 5).value = Saldo
                rng = rng + 1
            End If
        Loop

        wb.SHEETS(1).cells(rng, 2).value = "Totales"
        wb.SHEETS(1).cells(rng, 3).value = Cargos
        wb.SHEETS(1).cells(rng, 4).value = Abonos
        wb.SHEETS(1).cells(rng, 5).value = Saldo
        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next
        rng = rng + 2

        wb.SHEETS(1).cells(rng, 2).value = "Totales Generales"
        wb.SHEETS(1).cells(rng, 3).value = TotalCargos
        wb.SHEETS(1).cells(rng, 4).value = TotalAbonos
        wb.SHEETS(1).cells(rng, 5).value = SaldoTotal
        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next

        wb.SHEETS(1).columns(3).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(4).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(5).numberformat = "#,##0.00"

        wb.SHEETS(1).COLUMNS(1).ColumnWidth = 10
        wb.SHEETS(1).COLUMNS(2).ColumnWidth = 25
        wb.SHEETS(1).COLUMNS(3).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(4).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(5).ColumnWidth = 15

        wb.SHEETS(1).cells(1, 1).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 1).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 1).value = "Estado de cuenta de " & Me.txtNombre.Text & " " & Me.txtPaterno.Text & " " & Me.txtMaterno.Text
        wb.SHEETS(1).cells(2, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(3, 1).value = "Todos los adeudos"
        wb.SHEETS(1).cells(3, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(4, 1).value = "Impreso por: " & usuarioactivo & " el " & Now().Day & "-" & Now().Month & "-" & Now().Year
        wb.SHEETS(1).cells(4, 1).FONT.SIZE = 8
    End Sub
    Sub EdoCtaInfonavit()
        Dim xl As Object
        Dim wb As Object
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer = 5

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim periodo As Integer = txtBimestreInfonavit.Text

        Dim strSql As String = "SELECT * FROM CargosInfonavit WHERE IdEmpleado=" & txtIDEmpleado.Text & " AND Bimestre=" & periodo & " ORDER BY Fecha"

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        rng = rng + 1
        wb.SHEETS(1).cells(rng, 1).value = "Fecha"
        wb.SHEETS(1).cells(rng, 2).value = "Concepto"
        wb.SHEETS(1).cells(rng, 3).value = "Cargos"
        wb.SHEETS(1).cells(rng, 4).value = "Abonos"
        wb.SHEETS(1).cells(rng, 5).value = "Saldo"
        For i = 1 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
        Next
        rng = rng + 1
        Dim Cargos As Double = 0
        Dim Abonos As Double = 0
        Dim Saldo As Double = 0

        Do While rdBuscar.Read()
            wb.SHEETS(1).cells(rng, 1).value = rdBuscar("Fecha")
            wb.SHEETS(1).cells(rng, 2).value = "Cargo de Infonavit del Bimestre " & periodo
            wb.SHEETS(1).cells(rng, 3).value = rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 4).value = 0
            Cargos = Cargos + rdBuscar("Monto")
            Saldo = Saldo + rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 5).value = Saldo
            rng = rng + 1
        Loop

        cnConn.Close()

        strSql = "SELECT Monto,FechaAplicacion " & _
                 "FROM Abonos INFONAVIT I INNER JOIN NominaGeneral N " & _
                 "ON I.IdNomina=N.IdNomina " & _
                 "WHERE IdEmpleado=" & txtIDEmpleado.Text & " AND Bimestre=" & periodo & " ORDER BY FechaAplicacion"

        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            wb.SHEETS(1).cells(rng, 1).value = rdBuscar("FechaAplicacion")
            wb.SHEETS(1).cells(rng, 2).value = "Abono de Infonavit del Bimestre " & periodo
            wb.SHEETS(1).cells(rng, 3).value = 0
            wb.SHEETS(1).cells(rng, 4).value = rdBuscar("Monto")
            Abonos = Abonos + rdBuscar("Monto")
            Saldo = Saldo - rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 5).value = Saldo
            rng = rng + 1
        Loop

        wb.SHEETS(1).cells(rng, 2).value = "Totales"
        wb.SHEETS(1).cells(rng, 3).value = Cargos
        wb.SHEETS(1).cells(rng, 4).value = Abonos
        wb.SHEETS(1).cells(rng, 5).value = Saldo
        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next
        rng = rng + 2

        wb.SHEETS(1).columns(3).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(4).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(5).numberformat = "#,##0.00"

        wb.SHEETS(1).COLUMNS(1).ColumnWidth = 10
        wb.SHEETS(1).COLUMNS(2).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(3).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(4).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(5).ColumnWidth = 15

        wb.SHEETS(1).cells(1, 1).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 1).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 1).value = "Estado de cuenta de " & Me.txtNombre.Text & " " & Me.txtPaterno.Text & " " & Me.txtMaterno.Text
        wb.SHEETS(1).cells(2, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(3, 1).value = "Infonavit"
        wb.SHEETS(1).cells(3, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(4, 1).value = "Impreso por: " & usuarioactivo & " el " & Now().Day & "-" & Now().Month & "-" & Now().Year
        wb.SHEETS(1).cells(4, 1).FONT.SIZE = 8

    End Sub
    Sub EdoCtaFonacot()
        Dim xl As Object
        Dim wb As Object
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer = 5

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim periodo As Integer = txtMesFonacot.Text

        Dim strSql As String = "SELECT * FROM CargosFonacot WHERE IdEmpleado=" & txtIDEmpleado.Text & " AND Mes=" & periodo & " ORDER BY Fecha"

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        rng = rng + 1
        wb.SHEETS(1).cells(rng, 1).value = "Fecha"
        wb.SHEETS(1).cells(rng, 2).value = "Concepto"
        wb.SHEETS(1).cells(rng, 3).value = "Cargos"
        wb.SHEETS(1).cells(rng, 4).value = "Abonos"
        wb.SHEETS(1).cells(rng, 5).value = "Saldo"
        For i = 1 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
        Next
        rng = rng + 1
        Dim Cargos As Double = 0
        Dim Abonos As Double = 0
        Dim Saldo As Double = 0

        Do While rdBuscar.Read()
            wb.SHEETS(1).cells(rng, 1).value = rdBuscar("Fecha")
            wb.SHEETS(1).cells(rng, 2).value = "Cargo de Fonacot del Bimestre " & periodo
            wb.SHEETS(1).cells(rng, 3).value = rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 4).value = 0
            Cargos = Cargos + rdBuscar("Monto")
            Saldo = Saldo + rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 5).value = Saldo
            rng = rng + 1
        Loop

        cnConn.Close()

        strSql = "SELECT Monto,FechaAplicacion " & _
                 "FROM AbonosFonacot I, NominaGeneral N " & _
                 "ON I.IdNomina=N.IdNomina " & _
                 "WHERE I.IdEmpleado=" & txtIDEmpleado.Text & " AND Mes=" & periodo & " ORDER BY FechaAplicacion"

        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            wb.SHEETS(1).cells(rng, 1).value = rdBuscar("FechaAplicacion")
            wb.SHEETS(1).cells(rng, 2).value = "Abono de Infonavit del Bimestre " & periodo
            wb.SHEETS(1).cells(rng, 3).value = 0
            wb.SHEETS(1).cells(rng, 4).value = rdBuscar("Monto")
            Abonos = Abonos + rdBuscar("Monto")
            Saldo = Saldo - rdBuscar("Monto")
            wb.SHEETS(1).cells(rng, 5).value = Saldo
            rng = rng + 1
        Loop

        wb.SHEETS(1).cells(rng, 2).value = "Totales"
        wb.SHEETS(1).cells(rng, 3).value = Cargos
        wb.SHEETS(1).cells(rng, 4).value = Abonos
        wb.SHEETS(1).cells(rng, 5).value = Saldo
        For i = 2 To 5
            wb.SHEETS(1).cells(rng, i).font.bold = True
            wb.SHEETS(1).cells(rng, i).font.italic = True
        Next
        rng = rng + 2

        wb.SHEETS(1).columns(3).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(4).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(5).numberformat = "#,##0.00"

        wb.SHEETS(1).COLUMNS(1).ColumnWidth = 10
        wb.SHEETS(1).COLUMNS(2).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(3).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(4).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(5).ColumnWidth = 15

        wb.SHEETS(1).cells(1, 1).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 1).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 1).value = "Estado de cuenta de " & Me.txtNombre.Text & " " & Me.txtPaterno.Text & " " & Me.txtMaterno.Text
        wb.SHEETS(1).cells(2, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(3, 1).value = "Infonavit"
        wb.SHEETS(1).cells(3, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(4, 1).value = "Impreso por: " & usuarioactivo & " el " & Now().Day & "-" & Now().Month & "-" & Now().Year
        wb.SHEETS(1).cells(4, 1).FONT.SIZE = 8

    End Sub


    Private Sub TodosLosAdeudosToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles TodosLosAdeudosToolStripMenuItem1.Click
        imprimetodas()

    End Sub

    Private Sub InfonavitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles InfonavitToolStripMenuItem.Click
        EdoCtaInfonavit()

    End Sub

    Private Sub FonacotToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles FonacotToolStripMenuItem.Click
        EdoCtaFonacot()

    End Sub

    Private Sub IndicarAdeudosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles IndicarAdeudosToolStripMenuItem.Click
        frmCuentasUnaOld.ShowDialog()
    End Sub

    Private Sub TodosLosAdeudosToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs)


    End Sub

    Private Sub datNacimiento_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles datNacimiento.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtNacimiento.Focus()
            txtNacimiento.SelectAll()

        End If
    End Sub
    Sub imprimetodasNew()
        Dim xl As Object
        Dim wb As Object
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add()
        wb = xl.activeworkbook
        Dim rng As Integer

        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim strSql As String = ""

        strSql = "select IdAdeudo,IdCuenta,Codigo,Nombre,tipo"
        strSql = strSql & " from AdeudosTradicionales"
        strSql = strSql & " order by Nombre"


        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Dim cuentausuario As String = txtCuentaContPAQ.Text
        cuentausuario = Mid(cuentausuario, 5)
        Dim cuentacompac As String
        Dim mes As Date = Now()

        Dim i As Integer
        rng = 6

        Dim TipoMov As Boolean
        Dim JalaSaldo As Double
        Dim importe As Double = 0
        Dim cargo As Double = 0
        Dim abono As Double = 0
        Dim Concepto As String
        Dim elPrimero As Boolean = False
        Dim codigo As String
        Dim idcuenta As Integer
        Dim tipo As String
        Dim cnConnSql As New SqlConnection
        cnConnSql.ConnectionString = ContabilidadConnection
        Dim strSqlSql As String = ""
        Dim cmdBuscarSQL As New SqlCommand
        Dim rdBuscarSQL As SqlDataReader

        Do While rdBuscar.Read()
            cnConnSql.ConnectionString = ContabilidadConnection
            cuentacompac = rdBuscar("Codigo").ToString.Trim
            cuentacompac = Mid(cuentacompac, 1, 4)
            codigo = cuentacompac & cuentausuario
            idcuenta = BuscarIntDatoContabilidad("cuentas", "id", "codigo='" & codigo & "'")
            tipo = rdBuscar("tipo").ToString.Trim
            strSqlSql = ""
            strSqlSql = "select *"
            strSqlSql = strSqlSql & " from MovimientosPoliza"
            strSqlSql = strSqlSql & " where idcuenta=" & idcuenta
            strSqlSql = strSqlSql & " order by fecha"

            cmdBuscarSQL.Connection = cnConnSql
            cmdBuscarSQL.CommandText = strSqlSql
            cnConnSql.Open()
            rdBuscarSQL = cmdBuscarSQL.ExecuteReader

            wb.SHEETS(1).cells(rng, 1).value = "Nombre: " & txtPaterno.Text.Trim & " " & txtMaterno.Text & " " & txtNombre.Text
            wb.SHEETS(1).cells(rng, 1).font.size = 12
            wb.SHEETS(1).cells(rng, 1).font.bold = -1
            rng = rng + 1
            wb.SHEETS(1).cells(rng, 1).value = tipo & " " & rdBuscar("Nombre")
            wb.SHEETS(1).cells(rng, 1).font.size = 9
            wb.SHEETS(1).cells(rng, 1).font.bold = -1
            rng = rng + 2
            wb.SHEETS(1).cells(rng, 1).value = "Fecha"
            wb.SHEETS(1).cells(rng, 2).value = "Concepto"
            wb.SHEETS(1).cells(rng, 3).value = "Referencia"
            wb.SHEETS(1).cells(rng, 4).value = "Cargos"
            wb.SHEETS(1).cells(rng, 5).value = "Abonos"
            wb.SHEETS(1).cells(rng, 6).value = "Saldo"
            For i = 1 To 6
                wb.SHEETS(1).cells(rng, i).font.size = 9
                wb.SHEETS(1).cells(rng, i).font.bold = -1
            Next
            rng = rng + 1
            rng = rng + 1

            Do While rdBuscarSQL.Read()
                TipoMov = rdBuscarSQL("TipoMovto")
                wb.SHEETS(1).cells(rng, 1).value = rdBuscarSQL("fecha")
                Concepto = rdBuscarSQL("Concepto").ToString.Trim
                If Concepto = "" Then
                    wb.SHEETS(1).cells(rng, 2).value = "Saldos Iniciales/Ajuste"
                Else
                    wb.SHEETS(1).cells(rng, 2).value = rdBuscarSQL("Concepto").ToString.Trim
                End If

                wb.SHEETS(1).cells(rng, 3).value = rdBuscarSQL("Referencia").ToString.Trim

                importe = rdBuscarSQL("importe")
                If TipoMov = False Then
                    wb.SHEETS(1).cells(rng, 4).value = importe
                    If tipo.Trim = "Adeudo" Then
                        JalaSaldo = JalaSaldo + importe
                    Else
                        JalaSaldo = JalaSaldo - importe
                    End If

                    cargo = cargo + importe
                Else
                    wb.SHEETS(1).cells(rng, 5).value = importe
                    If tipo.Trim = "Adeudo" Then
                        JalaSaldo = JalaSaldo - importe
                    Else
                        JalaSaldo = JalaSaldo + importe
                    End If

                    abono = abono + importe
                End If
                wb.SHEETS(1).cells(rng, 6).value = JalaSaldo
                For i = 1 To 6
                    wb.SHEETS(1).cells(rng, i).font.size = 9
                Next
                rng = rng + 1
            Loop
            wb.SHEETS(1).cells(rng, 3).value = "Totales"
            wb.SHEETS(1).cells(rng, 4).value = cargo
            wb.SHEETS(1).cells(rng, 5).value = abono
            wb.SHEETS(1).cells(rng, 6).value = JalaSaldo
            For i = 1 To 6
                wb.SHEETS(1).cells(rng, i).font.size = 9
                wb.SHEETS(1).cells(rng, i).font.bold = True
            Next
            rng = rng + 2
            wb.SHEETS(1).cells(rng, 3).value = "Total " & tipo & ": "
            wb.SHEETS(1).cells(rng, 6).value = JalaSaldo
            For i = 1 To 6
                wb.SHEETS(1).cells(rng, i).font.size = 11
                wb.SHEETS(1).cells(rng, i).font.bold = True
            Next
            rng = rng + 2
            cnConnSql.Close()
            rdBuscarSQL.Close()

            cargo = 0
            abono = 0
            JalaSaldo = 0
        Loop

        wb.SHEETS(1).columns(4).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(5).numberformat = "#,##0.00"
        wb.SHEETS(1).columns(6).numberformat = "#,##0.00"

        wb.SHEETS(1).COLUMNS(1).ColumnWidth = 10
        wb.SHEETS(1).COLUMNS(2).ColumnWidth = 25
        wb.SHEETS(1).COLUMNS(3).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(4).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(5).ColumnWidth = 15
        wb.SHEETS(1).COLUMNS(6).ColumnWidth = 15


        wb.SHEETS(1).cells(1, 1).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 1).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 1).value = "Estado de cuenta de " & Me.txtNombre.Text & " " & Me.txtPaterno.Text & " " & Me.txtMaterno.Text
        wb.SHEETS(1).cells(2, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(3, 1).value = "Todos los adeudos"
        wb.SHEETS(1).cells(3, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(4, 1).value = "Impreso por: " & UsuarioActivo & " el " & Now().Day & "-" & Now().Month & "-" & Now().Year
        wb.SHEETS(1).cells(4, 1).FONT.SIZE = 8
    End Sub
    
    Private Sub datNacimiento_ValueChanged(sender As System.Object, e As System.EventArgs) Handles datNacimiento.ValueChanged
        Dim FechaParaDatos As Date = datNacimiento.Value
        Dim FechaTexto As String = ""
        FechaTexto = Mid(FechaParaDatos.Year, 3, 2)
        If FechaParaDatos.Month < 10 Then
            FechaTexto = FechaTexto & "0" & FechaParaDatos.Month
        Else
            FechaTexto = FechaTexto & FechaParaDatos.Month
        End If

        If FechaParaDatos.Day < 10 Then
            FechaTexto = FechaTexto & "0" & FechaParaDatos.Day
        Else
            FechaTexto = FechaTexto & FechaParaDatos.Day
        End If

        txtFechaRFC.Text = FechaTexto
        txtFechaCURP.Text = FechaTexto
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        lblPassword.Visible = True
        txtPassword.Visible = True
        txtPassword.Clear()
        txtPassword.Focus()
        txtPassword.SelectAll()





    End Sub

    Private Sub txtCodigo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCodigo.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            datIngreso.Focus()
            datIngreso.Select()
            CargaDatosDesdeNominas()
        End If
    End Sub

    Private Sub txtCodigo_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCodigo.TextChanged

    End Sub

    Private Sub datIngreso_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles datIngreso.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtPaterno.Focus()
            txtPaterno.SelectAll()

        End If
    End Sub

    Private Sub datIngreso_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datIngreso.ValueChanged

    End Sub

    Private Sub txtPaterno_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPaterno.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtMaterno.Focus()
            txtMaterno.SelectAll()

        End If
    End Sub

    Private Sub txtPaterno_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPaterno.TextChanged

    End Sub

    Private Sub txtMaterno_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMaterno.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtNombre.Focus()
            txtNombre.SelectAll()

        End If
    End Sub

    Private Sub txtMaterno_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMaterno.TextChanged

    End Sub

    Private Sub txtNombre_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNombre.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtDepartamento.Focus()
            txtDepartamento.SelectAll()

            btnDepto_Click(Me, System.EventArgs.Empty)
        End If
    End Sub

    Private Sub txtNombre_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNombre.TextChanged

    End Sub

    Private Sub txtDepartamento_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDepartamento.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtPuesto.Focus()
            txtPuesto.SelectAll()

            btnPuesto_Click(Me, System.EventArgs.Empty)
        End If
    End Sub

    Private Sub txtDepartamento_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDepartamento.TextChanged

    End Sub

    Private Sub txtPuesto_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPuesto.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtSD.Focus()
            txtSD.SelectAll()


        End If
    End Sub

    Private Sub txtPuesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPuesto.TextChanged

    End Sub

    Private Sub txtSDI_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSDI.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtPorcentaje.Focus()
            txtPorcentaje.SelectAll()

        End If
    End Sub

    Private Sub txtSDI_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSDI.TextChanged

    End Sub

    Private Sub txtPorcentaje_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPorcentaje.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            chGafete.Focus()
        End If
    End Sub

    Private Sub txtPorcentaje_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPorcentaje.TextChanged

    End Sub

    Private Sub datVencimientoGafete_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles datVencimientoGafete.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtFianza.Focus()
            txtFianza.SelectAll()

        End If
    End Sub

    Private Sub datVencimientoGafete_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datVencimientoGafete.ValueChanged

    End Sub

    Private Sub chGafete_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chGafete.CheckedChanged

    End Sub

    Private Sub chGafete_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles chGafete.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            datVencimientoGafete.Focus()
            datVencimientoGafete.Select()
        End If
    End Sub

    Private Sub txtFianza_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFianza.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCalle.Focus()
            txtCalle.SelectAll()

        End If
    End Sub

    Private Sub txtFianza_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFianza.TextChanged
       
    End Sub

    Private Sub txtCalle_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCalle.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtNumero.Focus()
            txtNumero.SelectAll()
        End If
        

    End Sub

    Private Sub txtCalle_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCalle.TextChanged

    End Sub

    Private Sub txtNumero_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumero.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtColonia.Focus()
            txtColonia.SelectAll()

        End If
    End Sub

    Private Sub txtNumero_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNumero.TextChanged

    End Sub

    Private Sub txtColonia_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtColonia.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCodigoPostal.Focus()
            txtCodigoPostal.SelectAll()

        End If
    End Sub

    Private Sub txtColonia_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtColonia.TextChanged

    End Sub

    Private Sub txtCodigoPostal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCodigoPostal.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtEstado.Focus()
            txtEstado.SelectAll()
        End If
    End Sub

    Private Sub txtCodigoPostal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCodigoPostal.TextChanged

    End Sub

    Private Sub txtEstado_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEstado.KeyDown
        If e.KeyValue = 13 Or e.KeyValue = 9 Then
            CargaCiudades()
            txtCiudad.Focus()
            txtCiudad.SelectAll()
        End If
    End Sub

    Private Sub txtEstado_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEstado.KeyPress
        
    End Sub

    Sub CargaCiudades()
        txtCiudad.AutoCompleteCustomSource = Nothing

        Dim cnconn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strSql As String
        Try
            cnconn.ConnectionString = InitialConnection
            strSql = "Select Ciudad FROM Entidades2 WHERE UPPER(Estado)='" & UCase(txtEstado.Text) & "' ORDER BY Ciudad"

            cmdBuscar.Connection = cnconn
            cmdBuscar.CommandText = strSql

            cnconn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                txtCiudad.AutoCompleteCustomSource.Add(rdBuscar("Ciudad").ToString.Trim)

            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try
    End Sub
    Sub CargaLugaresNacimiento()
        txtNacimiento.AutoCompleteCustomSource = Nothing

        Dim cnconn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strSql As String
        Try
            cnconn.ConnectionString = InitialConnection
            strSql = "Select Ciudad,Estado FROM Entidades2 ORDER BY Ciudad"

            cmdBuscar.Connection = cnconn
            cmdBuscar.CommandText = strSql

            cnconn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                txtNacimiento.AutoCompleteCustomSource.Add(rdBuscar("Ciudad").ToString.Trim & ", " & rdBuscar("Estado").ToString.Trim)

            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try
    End Sub
    Private Sub txtCiudad_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCiudad.KeyDown
        If e.KeyValue = 13 Or e.KeyValue = 9 Then
            txtTelefono.Focus()
            txtTelefono.SelectAll()
        End If
    End Sub

    Private Sub txtCiudad_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCiudad.TextChanged

    End Sub

    Private Sub txtTelefono_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTelefono.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCelular.Focus()
            txtCelular.SelectAll()

        End If
    End Sub

    Private Sub txtTelefono_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTelefono.TextChanged

    End Sub

    Private Sub txtCelular_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCelular.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtRecados.Focus()
            txtRecados.SelectAll()
        End If
    End Sub

    Private Sub txtCelular_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCelular.TextChanged

    End Sub

    Private Sub txtRecados_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRecados.KeyDown

    End Sub

    Private Sub txtRecados_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRecados.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            datNacimiento.Focus()
            datNacimiento.Select()

        End If
    End Sub

    Private Sub txtRecados_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRecados.TextChanged

    End Sub

    Private Sub txtNacimiento_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNacimiento.KeyDown
        If e.KeyValue = 13 Or e.KeyValue = 9 Then
            lstSexo.Focus()
            lstSexo.SelectAll()
        End If
    End Sub

    Private Sub txtNacimiento_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNacimiento.TextChanged

    End Sub

    Private Sub lstSexo_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles lstSexo.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            lstEstadoCivil.Focus()
            lstEstadoCivil.SelectAll()

        End If
    End Sub

    Private Sub lstSexo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSexo.SelectedIndexChanged

    End Sub

    Private Sub lstEstadoCivil_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles lstEstadoCivil.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            lstEscolaridad.Focus()
            lstEscolaridad.SelectAll()

        End If
    End Sub

    Private Sub lstEstadoCivil_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstEstadoCivil.SelectedIndexChanged

    End Sub

    Private Sub lstEscolaridad_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles lstEscolaridad.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtNSS.Focus()
            txtNSS.SelectAll()
        End If
    End Sub

    Private Sub lstEscolaridad_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstEscolaridad.SelectedIndexChanged

    End Sub

    Private Sub txtNSS_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNSS.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtRFC.Focus()
            txtRFC.SelectAll()

        End If
    End Sub

    Private Sub txtNSS_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNSS.TextChanged

    End Sub

    Private Sub txtRFC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtRFC.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtHomoclave.Focus()
            txtHomoclave.SelectAll()

        End If
    End Sub

    Private Sub txtRFC_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRFC.TextChanged

    End Sub

    Private Sub txtHomoclave_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtHomoclave.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCURP.Focus()
            txtCURP.SelectAll()

        End If
    End Sub

    Private Sub txtHomoclave_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtHomoclave.TextChanged

    End Sub

    Private Sub txtCURP_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCURP.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCURPF.Focus()
            txtCURPF.SelectAll()

        End If
    End Sub

    Private Sub txtCURP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCURP.TextChanged

    End Sub

    Private Sub txtCURPF_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCURPF.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtTarjeton.Focus()
            txtTarjeton.SelectAll()

        End If
    End Sub

    Private Sub txtCURPF_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCURPF.TextChanged

    End Sub

    Private Sub txtTarjeton_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTarjeton.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtLicencia.Focus()
            txtLicencia.SelectAll()

        End If
    End Sub

    Private Sub txtTarjeton_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTarjeton.TextChanged

    End Sub

    Private Sub txtLicencia_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLicencia.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            datVencimientoLicencia.Focus()
            datVencimientoLicencia.Select()

        End If
    End Sub

    Private Sub txtLicencia_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLicencia.TextChanged

    End Sub

    Private Sub datVencimientoLicencia_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles datVencimientoLicencia.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCuentaPago.Focus()
            txtCuentaPago.SelectAll()

        End If
    End Sub

    Private Sub datVencimientoLicencia_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datVencimientoLicencia.ValueChanged

    End Sub

    Private Sub txtCuentaPago_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCuentaPago.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtCuentaContPAQ.Focus()
            txtCuentaContPAQ.SelectAll()

        End If
    End Sub

    Private Sub txtCuentaPago_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCuentaPago.TextChanged

    End Sub

    Private Sub txtCuentaContPAQ_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCuentaContPAQ.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            txtDependientes.Focus()
            txtDependientes.SelectAll()
        End If
    End Sub

    Private Sub txtCuentaContPAQ_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCuentaContPAQ.TextChanged

    End Sub

    Private Sub txtDependientes_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDependientes.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            lstReligion.Focus()
            lstReligion.SelectAll()
        End If
    End Sub

    Private Sub txtDependientes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtDependientes.TextChanged

    End Sub

    Private Sub lstReligion_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles lstReligion.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Or e.KeyChar = Microsoft.VisualBasic.ChrW(9) Then
            ToolStripButton5_Click(Me, System.EventArgs.Empty)
        End If
    End Sub

    Private Sub lstReligion_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstReligion.SelectedIndexChanged

    End Sub

    Private Sub txtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            Dim PasswordTecleada As String = txtPassword.Text
            Dim PasswordAutoriza As String = BuscarStrDatoInicial("SELECT Password FROM Usuarios WHERE Nombre='KARINA'")
            If PasswordTecleada = PasswordAutoriza Then
                txtPassword.Visible = False
                lblPassword.Visible = False
                DesbloquearCampos()
                txtNSS.Focus()
                txtNSS.SelectAll()
            Else
                txtPassword.Visible = False
                lblPassword.Visible = False
                MsgBox("La contraseña no es valida", MsgBoxStyle.Exclamation, "Aviso")
            End If

        End If


    End Sub

    Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged

    End Sub

    Private Sub EvaluacionesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EvaluacionesToolStripMenuItem.Click
      
    End Sub

    Private Sub TodosLosAdeudosToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TodosLosAdeudosToolStripMenuItem.Click
        imprimetodasNew()
    End Sub

    Private Sub EliminarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarToolStripMenuItem1.Click
        Call SetSqlCitra("DELETE FROM OtrosCargos WHERE IdCargo=" & dgOtros.CurrentRow.Cells(0).Value)
        cargaOtros()

    End Sub

    Private Sub EliminarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminarToolStripMenuItem.Click

    End Sub

    Private Sub ReingresarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReingresarToolStripMenuItem.Click

    End Sub
End Class